2022-10-31

define anagram Python

Could anyone help? Need to define words on being Anagrams. But exactly the same words are not anagram. For example: cat - kitten The words aren't anagrams; cat - act The words are anagrams; cat - cat should be The same words. What should l do in this code to include The same words:

s1 = input("Enter first word:")
s2 = input("Enter second word:")
a = sorted(s for s in s1.lower() if s.isalpha())
b = sorted(s for s in s2.lower() if s.isalpha())
if sorted(a) == sorted(b):
    print("The words are anagrams.")
else:
    print("The words aren't anagrams.")


No comments:

Post a Comment