I know I can use the following syntax for loop in one line:
[print(x) for x in range(10)]
How can I use this syntax to combine two loops in one line?
I know I can use the following syntax for loop in one line:
[print(x) for x in range(10)]
How can I use this syntax to combine two loops in one line?
You can use code something like below. It allows iterating by an array of arrays.
x = [[2,5,6],[3,5,1]]
result = [[value[i] for value in x] for i in range(3)]
[(i, j) for i in range(10) for j in range(10)]
for instance or [[i for in range(j)] for j in range(10)]
and you can combine those ideas in any way you want