Python : 如何反转列表中子列表的顺序?

Python : How to reverse the order of sublist in a list?

我有一个由嵌套列表组成的列表。我想重新排列子列表的顺序。我尝试使用 list.reverse() 方法,但它反转了子列表的元素。我只想反转子列表的顺序而不是元素的顺序。

Input : [['25', '9', 'BID', 'toaster_1', '17.00'], ['26', '11', 'BID', 'toaster_1', '17.00']]
Expected Output : [['26', '11', 'BID', 'toaster_1', '17.00'],['25', '9', 'BID', 'toaster_1', '17.00']]

我使用了 array.reverse() 并且效果如你所愿。

The test

Output: [['26', '11', 'BID', 'toaster_1', '17.00'], ['25', '9', 'BID', 'toaster_1', '17.00']]
initial_list=[['25', '9', 'BID', 'toaster_1', '17.00'], ['26', '11', 'BID', 'toaster_1', '17.00']]
modified_list=initial_list[::-1] #reverse the list
print(modified_list)

代码中第2行反转list.From索引值-1