How to reverse a list of lists in python? [duplicate]

喜夏-厌秋 提交于 2021-02-16 15:06:33

问题


I was wondering how to reverse a list of lists in python. For example,

Original: list = [[1,2,3],[4,5,6],[7,8,9]] Output: new_list = [[7,8,9],[4,5,6],[1,2,3]]

Right now, I am trying this:

new_list = reversed(list)

However, this doesn't seem to work.


回答1:


In [24]: L = [[1,2,3],[4,5,6],[7,8,9]]

In [25]: L[::-1]
Out[25]: [[7, 8, 9], [4, 5, 6], [1, 2, 3]]


来源:https://stackoverflow.com/questions/33578916/how-to-reverse-a-list-of-lists-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!