On Sun, Apr 3, 2011 at 9:58 AM, Mag Gam <magaw...@gmail.com> wrote:
> I suppose I can do something like this.
> (pseudocode)
>
> d={}
> try:
>  d[key]+=1
> except KeyError:
>  d[key]=1
>
>
> I was wondering if there is a pythonic way of doing this? I plan on
> doing this many times for various files. Would the python collections
> class be sufficient?

I think you want collections.Counter. From the docs: "Counter objects
have a dictionary interface except that they return a zero count for
missing items instead of raising a KeyError".

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to