Why is this slower?
Stefan Behnel
stefan_ml at behnel.de
Mon Oct 5 13:42:16 EDT 2009
Joseph Reagle wrote:
> I would think the commented code would be faster (fewer loops), but it is
> not (because of function calls).
You just answered your own question.
> inSRC = set([bio.name for bio in bios.values()])
Note that this is actually very inefficient as it first creates a list of
values, then iterates over them to create a new list, and then creates a
set from that result. Py3 has set comprehensions, but in Py2.5+, you might
want to try .itervalues() and a generator expression instead.
Stefan
More information about the Python-list
mailing list