>>> key = ''.join(sorted(word))

I tend to strip and lower the word as well, otherwise "Hello" and
"hello" do not compare...depends on what you want though!
Plus you might get a lot of "word\n" as keys...

My technique is the this way

def anagram_finder(words):
    anagrams = {}
    for word in words:
        word = word.strip()
        key = ''.join(sorted(word.lower()))
        anagrams.setdefault(key, []).append(word)
    return anagrams
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to