Python: Multi list comprehension, is there such an unwieldy beast of prey ?

Posted by bandana on Stack Overflow See other posts from Stack Overflow or by bandana
Published on 2010-05-06T17:30:57Z Indexed on 2010/05/06 17:38 UTC
Read the original article Hit count: 234

Filed under:
|

consider the following python 'code'. it demonstrates the concept of a multi-list comprehension:

start  = ['a', 'b', 'c']
middle = ['r', 'a', 'a']
finish = ['t', 'r', 't']

l = [s.upper() + m + f for s in start,
                           m in middle,
                           e in finish]
>>> print l
['Art', 'Bar', 'Cat']

Alas, the above code does not work in python.

What would be a good approximation of multi-list comprehension in python?

Please discuss what happens when the lists have different lengths.

© Stack Overflow or respective owner

Related posts about python

Related posts about list-comprehension