Re: Using dictionary key as a regular expression class

2010-01-23 Thread Steve Holden
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(): >> tcoun

Re: Using dictionary key as a regular expression class

2010-01-23 Thread Chris Jones
On Sat, Jan 23, 2010 at 02:45:41AM EST, Terry Reedy wrote: > On 1/22/2010 9:58 PM, Chris Jones wrote: >> Do you mean I should just read the file one character at a time? > > Whoops, my misdirection (you can .read(1), but this is s l o w. > I meant to suggest processing it a char at a time. R

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Terry Reedy
On 1/22/2010 9:58 PM, Chris Jones wrote: On Fri, Jan 22, 2010 at 08:46:35PM EST, Terry Reedy wrote: Do you mean I should just read the file one character at a time? Whoops, my misdirection (you can .read(1), but this is s l o w. I meant to suggest processing it a char at a time. 1. If

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Chris Jones
On Fri, Jan 22, 2010 at 08:46:35PM EST, Terry Reedy wrote: > On 1/22/2010 4:47 PM, Chris Jones wrote: >> I was writing a script that counts occurrences of characters in source code >> files: >> >> #!/usr/bin/python >> import codecs >> tcounters = {} >> f = codecs.open('/home/gavron/git/screen/src/

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Terry Reedy
On 1/22/2010 4:47 PM, Chris Jones wrote: I was writing a script that counts occurrences of characters in source code files: #!/usr/bin/python import codecs tcounters = {} f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") for uline in f: lline = [] for char in uline[:-1

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Chris Jones
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 tco

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Arnaud Delobelle
Chris Jones writes: > I was writing a script that counts occurrences of characters in source > code files: > > #!/usr/bin/python > import codecs > tcounters = {} > f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") > for uline in f: > lline = [] > for char in uline[:-1]: >