python中实现列表的倒序排列

 

1、

>>> a = ["aaa","bbb","ccc","ddd"]
>>> b = reversed(a)
>>> c = []
>>> for i in b:
    c.append(i)

    
>>> c
['ddd', 'ccc', 'bbb', 'aaa']

 

2、

>>> a = ["aaa","bbb","ccc","ddd"]
>>> a.reverse()
>>> a
['ddd', 'ccc', 'bbb', 'aaa']

 

posted @ 2021-02-22 17:54  小鲨鱼2018  阅读(457)  评论(0编辑  收藏  举报