I am a novice in python. I wanted to create a list in a single line:
>>> x = [[-1, y] for y in range(-1, 2), [0, 1], [1, z] for z in range(1, -2, -1), [0, -1]]
to get :
>>>> x = [[-1, -1], [-1, 0], [-1, 1], [0, 1], [1, 1], [1, 0], [1, -1], [0, -1]]
but it gave error : name 'z' is not defined. So I had to do it with for loops and single pairs on separate lines, appending each time. Before that I did :
>>> x = [[-1, y] for y in range(-1, 2),[0, 1]]
>>> x
[[-1, [-1, 0, 1]], [-1, [0, 1]]]
which tells me y is taken as iterator of for loop as well as [0, 1]. I am wrongly corelating comma in C and python. How do I achieve what I intend to do (in a single line) ? (I know that I could do it directly since its a small range. But what if there was a bigger one?)
[ [y,z] for y in range(-1, 2) for z in range(-1, 2)]. Please explain yourself better.[-1, -1]) and lists of lists of ints ([[1,1], [1,0], [1, -1]]).