Documentation for iteration in mappings

D

Dennis Benzinger

Hi!

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? :)

Bye,
Dennis
 
?

=?ISO-8859-15?Q?Michael_Str=F6der?=

Dennis said:
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..... print x
....
Traceback (most recent call last):

Ciao, Michael.
 
S

Steven D'Aprano

Dennis said:
I must be blind because I didn't find anything in the documentation
which says iterating over an dictionary iterates over its keys. [snip]
Where is this information hidden? :)

You should examine your program. Simply pasting the code above to the
Python shell fails as expected:

Yes, this is true, but also irrelevant. The question isn't about the code,
but about the documentation.

The answer does appear to be hidden quite deeply. I had to dig out an old
"What's New" for version 2.2 to find it, hidden away in a section on
iterators:

http://aspn.activestate.com/ASPN/do...w/2.2/index.html#SECTION000400000000000000000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,338
Members
48,026
Latest member
DannieKeeg

Latest Threads

Top