Questiion on list

SiverFish occeanlinux at linuxmail.org
Thu Jun 27 11:32:28 EDT 2002


On Thu, 27 Jun 2002 05:11:06 +0000, Quinn Dunkan wrote:

> On Thu, 27 Jun 2002 14:36:03 +0000, SiverFish
> <occeanlinux at linuxmail.org> wrote:
>>I got the list of words now i want to calculate how many word in that
>>list which is the same word (insensitive case),can anyone show me how to
>>do it for example ls = ['abc','cd','abc','adf',abc','dwc','cd'] it will
>>show abc = 3 ,cd = 2, adf = 1, dwc=1
> 
> import string
> d = {}
> for e in map(string.lower, ls):
>     d[e] = d.get(e, 0) + 1
> freqs = [ (count, w) for w, count in d.items() ] freqs.sort()
> freqs.reverse()
> print ', '.join([ '%s = %d' %(count, w) for count, w in freqs ])

Could you  do it in python 1.5.2 and explain clearly to me please 
How about we have to do the same problem here when read in the multiple
files,Thank a lot



More information about the Python-list mailing list