-3

I have a list which is made up of nested lists. I want to rearrange the order of sublists. I tried using the list.reverse() method, however it reverses the elements of the sublist. I want to reverse just the order of sublist rather than the elements.

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']]
Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
user6662097
  • 47
  • 1
  • 7

2 Answers2

3
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)

The 2nd line in the code reverse the list.From index value -1

0

I used array.reverse() and it worked as you wanted.

The test

Output: [['26', '11', 'BID', 'toaster_1', '17.00'], ['25', '9', 'BID', 'toaster_1', '17.00']]
deltastar
  • 45
  • 1
  • 10