Using dictionary key as a regular expression class

Steve Holden steve at holdenweb.com
Sat Jan 23 12:37:38 CET 2010


Chris Jones wrote:
> 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. :-)
> 
Congratulations. That perception shows a sound appreciation of Python's
design.

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/




More information about the Python-list mailing list