Documentation for iteration in mappings
Michael Ströder
michael at stroeder.com
Tue Oct 25 12:02:47 EDT 2005
Dennis Benzinger wrote:
>
> I must be blind because I didn't find anything in the documentation
> which says iterating over an dictionary iterates over its keys.
>
> For example
>
> a_dictionary = {0: "zero", 1: "one"}
> for x in a:
> print x
>
> gives you
>
> 0
> 1
>
> Where is this information hidden? :)
You should examine your program. Simply pasting the code above to the
Python shell fails as expected:
$ python
Python 2.4.2 (#1, Oct 1 2005, 14:32:09)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a_dictionary = {0: "zero", 1: "one"}
>>> for x in a:
... print x
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'a' is not defined
>>>
Ciao, Michael.
More information about the Python-list
mailing list