letter frequency counter / your thoughts..
Paul Hankin
paul.hankin at gmail.com
Wed May 7 17:23:22 EDT 2008
On May 7, 5:39 pm, umpsu... at gmail.com wrote:
> Here is my code for a letter frequency counter. It seems bloated to
> me and any suggestions of what would be a better way (keep in my mind
> I'm a beginner) would be greatly appreciated..
Yours is a little more efficient than this, but here's a compact way
to write what you want.
import heapq
def mostfreq(message):
return heapq.nlargest(3, set(message), key=message.count)
--
Paul Hankin
More information about the Python-list
mailing list