Reputation: 2126
for item in "1,2,3,4,5,6".split(","):
I need to reverse the list to have first 6, then 5... Does an idea come to your mind how to do it more effectively than reverse it first and then use it? Some function I don't know yet?
Upvotes: 0
Views: 56
Reputation: 1121564
Use the reversed()
function:
for item in reversed("1,2,3,4,5,6".split(",")):
Demo:
>>> for item in reversed("1,2,3,4,5,6".split(",")):
... print item
...
6
5
4
3
2
1
Upvotes: 5