-3

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]]
fufes
  • 1
  • 3

4 Answers4

1

The task is basically inverting a list

e4 = e2[::-1]

reverting also the elements would be

e4 = [el[::-1] for el in e2[::-1]]
ME44
  • 26
  • 2
0

You just need to reverse the list. You can use list slicing for this, like so:

e4 = e2[::-1]
print(e4)

Output


[[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.

Melvin Abraham
  • 2,870
  • 5
  • 19
  • 33
0
   e2 = [
     [255,191,127],
     [191,127, 63],
     [127, 63, 0]]
    
    e2.reverse()
    e4 = e2
    for i in e4:
     print(i)
  • 1
    Note: `reverse` is a void. You will need to first call it then assign. –  Nov 14 '20 at 13:48
0

All you need to do is call list.reverse:

e2.reverse()
e4 = e2