python中实现列表元素的倒序排列
1、
>>> a = ["ccc","aaa","ddd","bbb"] ## 利用列表分片
>>> b = a[::-1]
>>> b
['bbb', 'ddd', 'aaa', 'ccc']
2、
>>> a = ["ccc","aaa","ddd","bbb"]
>>> b = []
>>> for i in reversed(a): ## 生成反转跌代体
b.append(i)
>>> b
['bbb', 'ddd', 'aaa', 'ccc']
3、
>>> a = ["ccc","aaa","ddd","bbb"]
>>> a.reverse() ## 原地反转
>>> a
['bbb', 'ddd', 'aaa', 'ccc']
4、
>>> a = ["ccc","aaa","ddd","bbb"]
>>> b = []
>>> for i in range(len(a)):
b.append(a.pop()) ## 利用pop
>>> b
['bbb', 'ddd', 'aaa', 'ccc']