php vs python

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


Afanasiy wrote:

> On Sat, 4 Jan 2003 21:21:05 -0500, pythonhda
> <pythonhda at yahoo.com.replacepythonwithlinux> 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 alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ We'll have to make our own luck from now on.
\__/ Louis Wu
    Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
 A personal guide to Quake III Arena.




More information about the Python-list mailing list