better way to do this in python
rosuav at gmail.com
Sat Apr 2 20:24:10 EDT 2011
On Sun, Apr 3, 2011 at 9:58 AM, Mag Gam <magawake at gmail.com> wrote:
> I suppose I can do something like this.
> except KeyError:
> 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".
More information about the Python-list