How can I swap the first 2 rows of a 2D Python list without using Numpy?
For example, if my list is:
lst = [[0,3,2],
[4,3,2],
[3,5,2]]
I want to swap [0,3,2] with [4,3,2].
Thanks!
>Solution :
Something like this? Or do you need it to be a function to swap when needed?
lst = [[0,3,2],
[4,3,2],
[3,5,2]]
lst[0], lst[1] = lst[1], lst[0]
print(lst)
# [[4, 3, 2],
# [0, 3, 2],
# [3, 5, 2]