-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
  • 4,846
  • 3
  • 21
  • 54
1

Use reversed such as ,

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

output:

[5, 4, 3, 2, 1]
Prathamesh
  • 1,004
  • 1
  • 5
  • 14