Iterating over a dictionary

Thomas Gagne tgagne at ix.netcom.com
Wed Aug 9 07:12:02 EDT 2000


If I were iterating over a dictionary, I would expect each "member" would be
each association.  It may be because of my smalltalk background but I see a
dictionary as just a collection of associations, or at least it should behave
that way.

As it turns out, iterating over a dictionary didn't work for my
purpose--creating a packed representation of a C structure, because the
associations woule re-order themselves (probably by hash value) so when I went
to assemble the structure the variables were out of order.

I ended up using a tuple (neat stuff - I'm getting to like Python).  What I
really liked was:

for x,y in myTyple:
    do something with x and y

Now THAT'S slick.




More information about the Python-list mailing list