Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 436
Jenny Avatar asked Jan 07 '23 05:01

Jenny


1 Answers

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]]
like image 177
inspectorG4dget Avatar answered Jan 09 '23 18:01

inspectorG4dget