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
07dc9180
Commit
07dc9180
authored
Jun 25, 2002
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close bug 480337: Dict used before dicts explained. Added explanation
and examples of the dict() constructor.
parent
04e7e0c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
Doc/tut/tut.tex
Doc/tut/tut.tex
+11
-2
No files found.
Doc/tut/tut.tex
View file @
07dc9180
...
...
@@ -1843,8 +1843,6 @@ parenthesized.
[12, 18]
>>> [3*x for x in vec if x < 2]
[]
>>> [
{
x: x**2
}
for x in vec]
[
{
2: 4
}
,
{
4: 16
}
,
{
6: 36
}
]
>>> [[x,x**2] for x in vec]
[[2, 4], [4, 16], [6, 36]]
>>> [x, x**2 for x in vec] # error - parens required for tuples
...
...
@@ -2023,6 +2021,17 @@ Here is a small example using a dictionary:
1
\end{verbatim}
The
\function
{
dict()
}
contructor builds dictionaries directly from
lists of key-value pairs stored as tuples. When the pairs form a
pattern, list comprehensions can compactly specify the key-value list.
\begin{verbatim}
>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
{
'sape': 4139, 'jack': 4098, 'guido': 4127
}
>>> dict([(x, x**2) for x in vec]) # use a list comprehension
{
2: 4, 4: 16, 6: 36
}
\end{verbatim}
\section
{
Looping Techniques
\label
{
loopidioms
}}
...
...
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