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 > Tutorial > List Comprehensions
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Retro, ezio.melotti, georg.brandl, mark.dickinson
Priority: low Keywords:

Created on 2009-07-13 14:57 by Retro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg90486 - (view) Author: Boštjan Mejak (Retro) Date: 2009-07-13 14:57
There's a mistake in the code snippet:

>>> freshfruit = ['  banana', '  loganberry ', 'passion fruit  ']
>>> [weapon.strip() for weapon in freshfruit]
['banana', 'loganberry', 'passion fruit']


The second line should be:
>>> [fruit.strip() for fruit in freshfruit]
['banana', 'loganberry', 'passion fruit']


The old code snippet had weapons as items which many people didn't like,
so the code snippet was changed into a friendlier version. Please fix
this code snippet so that weapons are not involved here, even though the
code is not broken. Thank you.
msg90487 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-07-13 15:15
That example was introduced in r16743 as:
>>> spcs = ["  Apple", " Banana ", "Coco  nut  "]
>>> print [s.strip() for s in spcs]
['Apple', 'Banana', 'Coco  nut']

and was changed in r16831 to:
>>> freshfruit = ['  banana', '  loganberry ', 'passion fruit  ']
>>> [weapon.strip() for weapon in freshfruit]
['banana', 'loganberry', 'passion fruit']

I think that the fresh fruits can really be considered as dangerous
weapons - especially the banana. <wink>
msg90488 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-07-13 15:20
> I think that the fresh fruits can really be considered as dangerous
> weapons.

Indeed.  Google for "monty python self-defence against fresh fruit".
msg90505 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-07-13 21:59
Retro, you still won't give up, will you?
History
Date User Action Args
2022-04-11 14:56:50adminsetgithub: 50724
2009-07-13 21:59:20georg.brandlsetstatus: pending -> closed

messages: + msg90505
2009-07-13 15:21:12mark.dickinsonsetstatus: open -> pending
2009-07-13 15:20:58mark.dickinsonsetstatus: pending -> open
nosy: + mark.dickinson
messages: + msg90488

2009-07-13 15:15:58ezio.melottisetstatus: open -> pending
priority: low

nosy: + ezio.melotti
messages: + msg90487

resolution: rejected
2009-07-13 14:57:39Retrocreate