Python - Anagrams

Check For Anagrams

  • This has to be the easiest way ever to check for anagram.

This ditti imports the collections library and uses sets.

from collections import Counter
def is_anagram(word1, word2):
    """Checks whether the words are anagrams.
    word1: string
    word2: string
    returns: boolean
    """
    return Counter(str1) == Counter(str2) 

collections Man Page

Counter Man Page