[docs] Extra list comprehension example

Ruud Althuizen ruud at stack.nl
Mon Apr 26 10:42:06 CEST 2010


Hello,

I was struggling to find an example of list comprehension for a specific
situation. The current examples only show if you want to:
- Use two loops concurently using non-dependent iterations
- Swap values

My situation is related to option 1: use one loop that depends on the other
loop.

I found one example[1] that makes obvious what I want to do (I had swapped
the two loops while experimenting):
    [ expression
      for line in open('file.txt')
      for char in line.strip() ]

I believe this would be an helpfull example to add to
http://docs.python.org/tutorial/datastructures.html#list-comprehensions


1: http://rhodesmill.org/brandon/2009/nested-comprehensions/

-- 
Met vriendelijke groet,
Ruud Althuizen
- www.stack.nl
- Unix commissie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/docs/attachments/20100426/2c9550fc/attachment.pgp>


More information about the docs mailing list