0
How many ways are there to reverse a list?
Using functions and loops. take L=[1, 2, 3, 4]
5 Answers
+ 14
well here is one way
https://code.sololearn.com/c0204qSqESx4/?ref=app
specifically thing.reverse()
+ 5
This one only works with lists of unique elements:
L = [1,2,3,4,5]
M = [L[len(L)-L.index(i)-1] for i in L]
print(M)
+ 4
L = [1,2,3,4,5]
M = [L[len(L)-1-i] for i in range(len(L))]
print(M)
>>>
[5, 4, 3, 2, 1]
0
L.reverse() and
L=L[::-1] are simple ways. Please tell me other ways for reverse it.
0
what the function 'reversed()' returns if we put list in this as argument. what reversed() use?