This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Documentation correction - 5.1.4. List Comprehensions
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Liang.Zhang, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2015-01-22 08:53 by Liang.Zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg234485 - (view) Author: Liang Zhang (Liang.Zhang) Date: 2015-01-22 08:53
This was copied from Chapter 5 Data Structure in Python language tutorial.

The link I was looking for:  https://docs.python.org/2.7/tutorial/datastructures.html

Some thing might be incorrect and need you to update them in
(5.1.4. List Comprehensions)

It should be like this:
------------------start------------------
>>> vec = [-4, -2, 0, 2, 4]
>>> # create a new list with the values doubled
>>> [x*2 for x in vec]
[-8, -4, 0, 4, 8]
>>> # filter the list to exclude negative numbers
>>> [x for x in vec if x >= 0]
[0, 2, 4]
>>> # apply a function to all the elements
>>> [abs(x) for x in vec]
[4, 2, 0, 2, 4]                     >>>>>>>>>>>It should be [0, 2, 4]<<<<<<<<<<<
------------------end------------------
msg234496 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-01-22 15:43
vec has not been changed.  The example is correct.  Give it a try :)
msg234534 - (view) Author: Liang Zhang (Liang.Zhang) Date: 2015-01-23 01:30
Oh my god! You're right!
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67488
2015-01-23 01:30:22Liang.Zhangsetmessages: + msg234534
2015-01-22 15:43:40r.david.murraysetstatus: open -> closed

type: resource usage -> behavior

nosy: + r.david.murray
messages: + msg234496
resolution: not a bug
stage: resolved
2015-01-22 08:53:41Liang.Zhangcreate