anagram.py

1
2
3
4
5
6
7
8
9
10
11
12
def detect_anagrams(word, anagrams):
    word = word.lower()
    letters = sorted(word)

    def is_anagram(other):
        """
        Determine whether `other` is an anagram of (but not equal to) word
        """
        other = other.lower()
        return other != word and sorted(other) == letters

    return filter(is_anagram, anagrams)

@jcromero thinks this looks great

Comments

Brought is_anagram inside so we only sort the word once.

helenst commented 25 April 2016 at 07:45 UTC

You're not logged in right now. Please login via GitHub to comment