0

How can you reverse a list on python

I have been trying to reverse a list with this code: list = [1,2,3,4,5] print list(reversed(l)) And I dont understand why it is wrong

28th Mar 2018, 3:16 PM
Khoa Gia Le
Khoa Gia Le - avatar
2 Respostas
0
Add parenthesis after the print function. print(list(reversed(l))) In 3.x Python print is a function not a keyword.
28th Mar 2018, 3:25 PM
TurtleShell
TurtleShell - avatar
0
You can reverse list using slicing notation : reversed_list = list[::-1] The difference is that slicing notation return a new list object while reversed() function return an iterator object...
28th Mar 2018, 3:35 PM
visph
visph - avatar