Generator slower than iterator?
rdmurray at bitdance.com
rdmurray at bitdance.com
Tue Dec 16 11:29:36 EST 2008
Quoth Lie Ryan <lie.1296 at gmail.com>:
> On Tue, 16 Dec 2008 12:07:14 -0300, Federico Moreira wrote:
>
> > Hi all,
> >
> > Im parsing a 4.1GB apache log to have stats about how many times an ip
> > request something from the server.
> >
> > The first design of the algorithm was
> >
> > for line in fileinput.input(sys.argv[1:]):
> > ip = line.split()[0]
> > if match_counter.has_key(ip):
> > match_counter[ip] += 1
> > else:
> > match_counter[ip] = 1
>
> nitpick:
> dict.has_key is usually replaced with
> if ip in match_counter: ...
I'd say it's just slightly more than a nitpick nowadays: since Python
3.0 does not support has_key, it's time to get used to not using it :)
--RDM
More information about the Python-list
mailing list