0

How many ways are there to reverse a list?

Using functions and loops. take L=[1, 2, 3, 4]

17th Apr 2017, 4:52 AM
Chitransh M
Chitransh M - avatar
5 Antworten
+ 14
well here is one way https://code.sololearn.com/c0204qSqESx4/?ref=app specifically thing.reverse()
17th Apr 2017, 5:41 AM
Ahri Fox
Ahri Fox - avatar
+ 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)
17th Apr 2017, 7:55 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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]
17th Apr 2017, 7:51 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
L.reverse() and L=L[::-1] are simple ways. Please tell me other ways for reverse it.
17th Apr 2017, 5:46 AM
Chitransh M
Chitransh M - avatar
0
what the function 'reversed()' returns if we put list in this as argument. what reversed() use?
17th Apr 2017, 8:51 AM
Chitransh M
Chitransh M - avatar