Using dictionary key as a regular expression class

Chris Jones cjns1989 at gmail.com
Sat Jan 23 00:38:44 CET 2010


On Fri, Jan 22, 2010 at 05:07:13PM EST, Arnaud Delobelle wrote:

[..]

> import codecs
> from collections import defaultdict
> 
> tcounters = defaultdict(int)
> f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8")
> 
> for c in f.read():
>     tcounters[c] += 1
> 
> for c, n in tcounters.iteritems():
>     print "%r\t%i" % (c, n)

Ah, yes.. much better - I grew suspicious of my 'effort' when I realized
I could have written a shorter version in C. :-)

CJ



More information about the Python-list mailing list