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
bbf4ae51
Commit
bbf4ae51
authored
Sep 30, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
Merge #21739: mention subtle difference between loops and listcomps in tutorial.
parents
5a789f7e
6bd68608
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
Doc/tutorial/datastructures.rst
Doc/tutorial/datastructures.rst
+8
-3
No files found.
Doc/tutorial/datastructures.rst
View file @
bbf4ae51
...
...
@@ -200,12 +200,17 @@ For example, assume we want to create a list of squares, like::
>>> squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
We can obtain the same result with::
Note that this creates (or overwrites) a variable named ``x`` that still exists
after the loop completes. We can calculate the list of squares without any
side effects using::
squares = list(map(lambda x: x**2, range(10)))
or, equivalently::
squares = [x**2 for x in range(10)]
This is also equivalent to ``squares = list(map(lambda x: x**2, range(10)))``,
but it's more concise and readable.
which is more concise and readable.
A list comprehension consists of brackets containing an expression followed
by a :keyword:`for` clause, then zero or more :keyword:`for` or :keyword:`if`
...
...
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