String &Regular Expressions
Write a python script to take two string S1 and S2 and do the following:
Check S1 and S2 are anagrams or not.
Check S1 is Sub string of S2 or not.
S1 is palindrome or not
def is_anagram(s1, s2):
if len(s1) != len(s2):
return False
for ch in s1:
if ch not in s2:
return False
s2 = s2.replace(ch, "" , 1)
return True
def sub_string(s1, s2):
if s1 in s2:
return True
return False
def is_palindrome(s):
if s ==s[::-1]:
return True
return False
s1 = input('s1: ')
s2 = input('s2: ')
print("s1 and s2 are anagrams:",is_anagram(s1, s2))
print("s1 sub string s2",sub_string( s1, s2))
print("s1 is palindrome:",is_palindrome( s1))
Comments
Leave a comment