DEV Community

Discussion on: Write a script to identify an anagram

Collapse
 
ayumukasuga profile image
Andrey Kostakov
def isAnagram(a, b):
    return a == b[::-1]
Collapse
 
evanoman profile image
Evan Oman

While this happens to work for stressed and desserts this only checks for words which are reverse copies of each other, not anagrams.

add and dad are anagrams (same letters) but this check does not catch it:

>>> def isAnagram(a, b):   
...     return a == b[::-1]
...                        
>>> isAnagram("dad", "add")
False