php vs python

aonaran at yahoo.com aonaran at yahoo.com
Tue Jan 7 21:57:21 CET 2003


Erik Max Francis <max at alcyone.com> wrote:
> aonaran at yahoo.com wrote:

>> With the introduction of iterators in python 2.2 (IIRC) it's even
>> simpler:
>> 
>>         for key, val in d.items():
>>             print key,'=',val

> This actually doesn't have anything to do with iterators, this has been
> good Python since 1.5.2 at least.  In 2.x, the dictionary itself is an
> iterable object and iterating over it is equivalent to iterating over
> its keys.

That's right, which is why "for key in d" works.

(looks at code in the message again, which doesn't do that at all, but 
uses the .items method to generate a list)

Er.  There were originally three examples there, of increasing simplicity,
until "for key in d"..


Doug "now-with-more-errors!-ly yours"




More information about the Python-list mailing list