Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a PYTHON function that checks whether two words are anagrams. Two words ar

ID: 3760744 • Letter: W

Question

Write a PYTHON function that checks whether two words are anagrams.

Two words are anagrams if they contain the same letters.

For example, silent and listen are anagrams. The header of the function is: def isAnagram(s1, s2):

(Hint: Create two lists from the two strings entered by the user. Sort the lists using sort method and check if two lists are identical.) Write a main function that prompts the user to enter two strings and displays the ouput: Sample output: The words silent and listen are anagrams The words silent and learning are not anagrams

Explanation / Answer

def anagrams(str1,str2):
str1List = list(str1)
str2List = list(str2)
str1List.sort()
str2List.sort()
  
if str1List == str2List:
print str1 + ' and '+str2+ ' are anagrams.'
else:
print str1 + ' and '+str2+ ' are not anagrams.'

str1 = raw_input('Enter string 1 : ')
str2 = raw_input('Enter string 2 : ')
anagrams(str1,str2)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote