python vs. grep

Ian Kelly ian.g.kelly at gmail.com
Tue May 6 15:50:55 EDT 2008


On Tue, May 6, 2008 at 1:42 PM, Anton Slesarev <slesarev.anton at gmail.com> wrote:
>  Is it possible to increase file reading performance?

Dunno about that, but this part:

>  flines = (line for line in f if pat.search(line))
>  c=0
>  for x in flines:
>     c+=1
>  print c

could be rewritten as just:

print sum(1 for line in f if pat.search(line))



More information about the Python-list mailing list