php vs python

Andrew Bennetts andrew-pythonlist at puzzling.org
Sun Jan 5 02:10:09 EST 2003


On Sun, Jan 05, 2003 at 06:51:56AM +0000, 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?
> 
> Wouldn't this code result in a no-index error on d[key] ?

Why don't you try running it?

bash-2.05b$ python
Python 2.2.2 (#1, Dec 18 2002, 10:36:37) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {'one': 1, 'two': 2, 'three': 3}
>>> for key in d:
...     print key, '=', d[key]
... 
three = 3
two = 2
one = 1
>>> 

Much faster than asking comp.lang.python :)

-Andrew.






More information about the Python-list mailing list