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?
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?
Use reversed
such as ,
x = [1, 2, 3, 4, 5]
print(list(reversed(x)))
output:
[5, 4, 3, 2, 1]