[Tutor] user-given variable names for objects
Kent Johnson
kent37 at tds.net
Thu Dec 13 22:24:34 CET 2007
Tiger12506 wrote:
> I may sound like a know-it-all, but dictionaries *are* iterators.
Mmm, to nit-pick a little, dictionaries are iterables, not iterators.
They don't have a next() method.
> [a for a in eventData if eventData[a] < time.time()]
>
> This is more efficient. The keys method creates a list in memory first and
> then it iterates over it.
I've never tested it but I suspect that when you need keys and values,
it is more efficient to use itervalues():
[ k for k, v in eventData.itervalues() if v < time.time() ]
and of course if you care about efficiency you should hoist the call to
time.time() out of the loop!
Kent
More information about the Tutor
mailing list