python list comprehension double for

Solutions on MaxInterview for python list comprehension double for by the best coders in the world

showing results for - "python list comprehension double for"
Liam
20 Aug 2016
1[x for y in collection for x in y] # [A for B in C for D in E]
Maite
09 Aug 2016
1>>> l = [(x,y) for x in range(0,3) for y in range(5, 8)]
2>>> l
3[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (1, 7), (2, 5), (2, 6), (2, 7)]
4
5# they can also be "chained"
6>>> l = [(x,y) for x in range(0,4) for y in range(0, x)]
7>>> l
8[(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]