41.3k views
0 votes
Write a 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: Obtain two lists for the two strings. Sort the lists and check if two lists are identical.)

Write a test program that prompts the user to enter two strings and checks whether they are anagrams.

Sample Run 1

Enter a string s1: silent

Enter a string s2: listen

silent and listen are anagrams

Sample Run 2

Enter a string s1: split

Enter a string s2: lisp

split and lisp are not anagrams

User Olivarsham
by
5.1k points

1 Answer

4 votes

Answer:

def isAnagram(s1, s2):

list1=s1

list2=s2

sortedlist1 = sorted(list1)

sortedlist2 = sorted(list2)

if sortedlist1 == sortedlist2:

print(list1+ " and "+list2+ " are anagram")

else:

print(list1+ " and "+list2+ " are not anagram")

Step-by-step explanation:

Here is a call to the function isAnagram():

list1 =input("Enter String1 ")

list1 =input("Enter String2 ")

isAnagram(list1,list2)

Attached is the run and output for this program

Write a function that checks whether two words are anagrams. Two words are anagrams-example-1
User Joe Shakely
by
5.1k points