[Tutor] user-given variable names for objects
Tiger12506
keridee at jayco.net
Sat Dec 15 17:32:20 CET 2007
> Mmm, to nit-pick a little, dictionaries are iterables, not iterators. They
> don't have a next() method.
I'm a little fuzzy on the details of that, I will have to look over some
reference material again.
>> [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() ]
Oh! This is new to me! When did they put in itervalues? See what happens
when you leave the python community so you can learn C and assembly~
> and of course if you care about efficiency you should hoist the call to
> time.time() out of the loop!
Oh, I thought it was necessary for the time to change within the loop which
might or might not be necessary, depending on just what exactly is supposed
to happen. I would guess that in an unordered data structure like that, it
wouldn't be of any use to update the time within the loop.
Ask me if you are curious and can't follow my reasoning.
More information about the Tutor
mailing list