Reverse a list in Python
When you want to reverse a list in python, you can use following things.
1) reversed function
>>> somelist = range(10,100,10)
>>> for i in reversed(somelist):
print i
2) reverse method of list
>>> somelist = range(10,100,10)
>>> somelist.reverse()
or
>>> somelist[::-1]
Thanks
Have Fun!
1) reversed function
>>> somelist = range(10,100,10)
>>> for i in reversed(somelist):
print i
2) reverse method of list
>>> somelist = range(10,100,10)
>>> somelist.reverse()
or
>>> somelist[::-1]
Thanks
Have Fun!
댓글
댓글 쓰기