-2

I want to change the first element by the last, the second element by the last but one, etc.. Then I want to print this.

My list:
x = [1, 2, 3, 4, 5]
I want this list as:
y = [5, 4, 3, 2, 1]

how can I do it in Python 3.x?

Shakib
  • 27
  • 7

2 Answers2

1

A simple way is the following:

y = x[::-1]
Md Johirul Islam
  • 5,042
  • 4
  • 23
  • 56
1

Use reversed such as ,

x = [1, 2, 3, 4, 5]
print(list(reversed(x)))

output:

[5, 4, 3, 2, 1]
Prathamesh
  • 1,064
  • 1
  • 6
  • 16