TDT4109/Exercise 7/5.py

29 lines
784 B
Python

from re import search
def check_equal(str1, str2):
for char in range(len(str1)):
if str1[char] != str2[char]: return False
return True
def reversed_word(word):
return ''.join([word[len(word) - 1 - i] for i in range(len(word))])
def check_palindrome(string):
return string == reversed_word(string)
def contains_string(str1, str2):
match = search(pattern=str2, string=str1)
return match.span()[0] if match != None else -1
if __name__ == "__main__":
print(check_equal('hei', 'hello'))
print(check_equal('hello', 'hello'))
print()
print(reversed_word('star desserts'))
print()
print(check_palindrome('agnes i senga'))
print(check_palindrome('hello'))
print()
print(contains_string('pepperkake', 'per'))
print(contains_string('pepperkake', 'ola'))