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!


댓글

이 블로그의 인기 게시물

미국 포닥, 한국으로 돌아가는 이유? (Why do postdoc go back to Korea?)

미국 포닥 - 비지팅 포닥 VS 풀펀딩 포닥 (Visiting Scholar VS Postdoctoral Fellow)

미국 포닥 직위, 타이틀, 명칭? - Visiting Scholar, Postdoctoral Fellow, Research Associate, Research Scientist, Research Professor