for item in "1,2,3,4,5,6".split(","):
我需要将列表反转为前 6 个,然后是 5 个......您是否想到如何比先反转然后使用它更有效地做到这一点?一些我还不知道的功能?
使用reversed()
功能:
for item in reversed("1,2,3,4,5,6".split(",")):
演示:
>>> for item in reversed("1,2,3,4,5,6".split(",")):
... print item
...
6
5
4
3
2
1