List comprehensions: for and tuple : List Comprehensive « List « Python






List comprehensions: for and tuple

List comprehensions: for and tuple


print [x+y for x in 'spam' for y in 'SPAM']

print [(x,y) for x in range(5) if x%2 == 0 for y in range(5) if y%2 == 1]


           
       








Related examples in the same category

1.List comprehensions: map and tupleList comprehensions: map and tuple
2.List Comprehensions: a concise way to create lists
3.Define a function to construct listDefine a function to construct list
4.Find Prime numbers using listFind Prime numbers using list
5.List Comprehensions in buildConnectionString, Step by StepList Comprehensions in buildConnectionString, Step by Step