I have a question wether it is possible to reverse certain arrays in my 2D array. For example
a=[[1,2],[3,4],[5,6]]
a[1:3].reverse()
print(a)
would output:
[1,2],[5,6],[3,4]
I hope you can help :)
a = [[1, 2], [3, 4], [5, 6]]
a = a[:1] + list(reversed(a[1:3]))
print(a)
You could also use pure slicing, but imo the previous version is more readable:
a = a[:1] + a[:-3:-1]
a[1:3] creates a new list and because .reverse is an in-place method - a is not affected