[Tutor] Counting Items in a List

Alan Gauld alan.gauld at btinternet.com
Wed Jun 20 19:26:51 CEST 2012


On 20/06/12 16:20, Martin A. Brown wrote:

>   : should have written something like "counting how many times each
>   : word occured" insted of "counting words".
>
> You might like to try out collections.defaultdict().

Even a standard dict would simplify the code dramatically.
The defaultdict does suit this case better though.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list