Python list comprehension for loops
I'm reading the Python wikibook and feel confused about this part:
List comprehension supports more than one for statement. It will evaluate
the items in all of the objects sequentially and will loop over the
shorter objects if one object is longer than the rest.
>>>item = [x+y for x in 'cat' for y in 'pot']
>>>print item
['cp', 'co', 'ct', 'ap', 'ao', 'at', 'tp', 'to', 'tt']
I understand the usage of nested for loops but I don't get
...and will loop over the shorter objects if one object is longer than the
rest
What does this mean? (shorter, longer...)
No comments:
Post a Comment