Counting number of each item in a list.

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Mar 19 15:32:15 EST 2006


sophie_newbie a écrit :
> Hey Bruno,
> 
> I got an invalid syntax error when i tried using your "str_counts =
> dict((s, str_list.count(s) for s in set(str_list))" bit of code? Maybe
> there is a missing bracket or comma? 

Yes, sorry, see Kent's post for the correction.

> Or maybe I need to import
> something.

Nope, unless you're running python < 2.4




More information about the Python-list mailing list