0

while trying to print multiple rows and columns using list comprehensions, the following code works

X=[[x for x in range(y)] for y in range(3)]

but this code does not work

X=[x for x in range(y) for y in range(3)]

How these comprehensions work with multiple loops as generally for multiple loops it works from left to right. in this case the loops are working from right to left so we able to use y before y is declared in for .

user2779311
  • 1,534
  • 3
  • 21
  • 29

0 Answers0