anagram finder / dict mapping question

George Sakkis george.sakkis at gmail.com
Fri May 9 20:53:19 EDT 2008


On May 9, 5:19 pm, umpsu... at gmail.com wrote:
> > > 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?
>
> > You can use the max() function to find the biggest list of anagrams:
>
> > top_results = max(anagrams.itervalues(), key=len)
>
> > --
> > Arnaud
>
> That is the biggest list of anagrams, what if I wanted the 3 biggest
> lists?  Is there a way to specific top three w/ a max command??

>>> import heapq
>>> help(heapq.nlargest)
Help on function nlargest in module heapq:

nlargest(n, iterable, key=None)
    Find the n largest elements in a dataset.

    Equivalent to:  sorted(iterable, key=key, reverse=True)[:n]


HTH,
George



More information about the Python-list mailing list