php vs python

Erik Max Francis max at
Sun Jan 5 08:17:29 CET 2003

Afanasiy wrote:

> On Sat, 4 Jan 2003 21:21:05 -0500, pythonhda
> <pythonhda at> wrote:
> >for key in d:
> >       print key, '=', d[key]
> Someone please verify this example is incorrect.
> Putting the value in a variable named 'key' still
> makes it a value, not a key... Right?

In versions of Python that support it, one can iterate over dictionaries
where `for x in D' (where D is a dictionary) is equivalent to `for x in
D.keys()'.  Older version of Python do not support them.

> Wouldn't this code result in a no-index error on d[key] ?

In that code, on each iteration through the loop, key is the key; d[key]
is the value associated with that key in the dictionary d.

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ We'll have to make our own luck from now on.
\__/ Louis Wu Quake III Arena /
 A personal guide to Quake III Arena.

More information about the Python-list mailing list