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
2 Answers
0
Add parenthesis after the print function.
print(list(reversed(l)))
In 3.x Python print is a function not a keyword.
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...