anagram finder / dict mapping question

umpsumps at gmail.com umpsumps at gmail.com
Fri May 9 14:40:59 EDT 2008


On May 9, 1:45 am, cokofree... at gmail.com wrote:
> >>> 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

What would be the best method to print the top results, the one's that
had the highest amount of anagrams??  Create a new histogram dict?



More information about the Python-list mailing list