Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
dab1a13c
Commit
dab1a13c
authored
Aug 19, 2002
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend some comments on the order of values in the returns from
dict.items/keys/values/iteritems/iterkeys/itervalues().
parent
561df44b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
8 deletions
+14
-8
Doc/lib/libstdtypes.tex
Doc/lib/libstdtypes.tex
+14
-8
No files found.
Doc/lib/libstdtypes.tex
View file @
dab1a13c
...
...
@@ -1049,13 +1049,13 @@ arbitrary objects):
{
(6)
}
\lineiii
{
\var
{
a
}
.iteritems()
}
{
return an iterator over (
\var
{
key
}
,
\var
{
value
}
) pairs
}
{
(2)
}
{
(2)
, (3)
}
\lineiii
{
\var
{
a
}
.iterkeys()
}
{
return an iterator over the mapping's keys
}
{
(2)
}
{
(2)
, (3)
}
\lineiii
{
\var
{
a
}
.itervalues()
}
{
return an iterator over the mapping's values
}
{
(2)
}
{
(2)
, (3)
}
\end{tableiii}
\noindent
...
...
@@ -1067,11 +1067,17 @@ in the map.
\item
[(2)]
\versionadded
{
2.2
}
\item
[(3)]
Keys and values are listed in random order. If
\method
{
keys()
}
and
\method
{
values()
}
are called with no intervening
modifications to the dictionary, the two lists will directly
correspond. This allows the creation of
\code
{
(
\var
{
value
}
,
\var
{
key
}
)
}
pairs using
\function
{
zip()
}
:
\samp
{
pairs =
zip(
\var
{
a
}
.values(),
\var
{
a
}
.keys())
}
.
\method
{
items()
}
,
\method
{
keys()
}
,
\method
{
values()
}
,
\method
{
iteritems()
}
,
\method
{
iterkeys()
}
, and
\method
{
itervalues()
}
are called with no intervening modifications to the dictionary, the
lists will directly correspond. This allows the creation of
\code
{
(
\var
{
value
}
,
\var
{
key
}
)
}
pairs using
\function
{
zip()
}
:
\samp
{
pairs = zip(
\var
{
a
}
.values(),
\var
{
a
}
.keys())
}
. The same
relationship holds for the
\method
{
iterkeys()
}
and
\method
{
itervalues()
}
methods:
\samp
{
pairs = zip(
\var
{
a
}
.itervalues(),
\var
{
a
}
.iterkeys())
}
provides the same value for
\code
{
pairs
}
.
Another way to create the same list is
\samp
{
pairs = [(v, k) for (k,
v) in
\var
{
a
}
.iteritems()]
}
.
\item
[(4)]
Never raises an exception if
\var
{
k
}
is not in the map,
instead it returns
\var
{
x
}
.
\var
{
x
}
is optional; when
\var
{
x
}
is not
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment