Answer to Question #292354 in Python for sruthi

Question #292354

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

1
Expert's answer
2022-01-31T07:56:19-0500
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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS