How do i flip e2
so it becomes e4
?
input
e2 = [
[255,191,127],
[191,127, 63],
[127, 63, 0]]
output
e4 = [
[127, 63, 0],
[191,127, 63],
[255,191,127]]
The task is basically inverting a list
e4 = e2[::-1]
reverting also the elements would be
e4 = [el[::-1] for el in e2[::-1]]
You just need to reverse the list. You can use list slicing for this, like so:
e4 = e2[::-1]
print(e4)
[[127, 63, 0],
[191,127, 63],
[255,191,127]]
Here, [::-1]
means that you are slicing from the start of the list to the end of the list. The -1
tells Python to slice the list backwards, i.e., reverse it.
e2 = [
[255,191,127],
[191,127, 63],
[127, 63, 0]]
e2.reverse()
e4 = e2
for i in e4:
print(i)
All you need to do is call list.reverse
:
e2.reverse()
e4 = e2