I am trying to create a function that changes the order of items in a list, and also overrides items in a sublist. eg:
For example, if L = [[1, 2], [3, 4], [5, 6, 7]], then deep_reverse (L) mutates L as [[7, 6, 5], [4, 3], [2, 1]]
I figured out how to reorder a single list, but I am having problems reordering items in a sublist. This is what I have so far:
def deep_reverse(L)
"""
assumes L is a list of lists whose elements are ints
Mutates L such that it reverses its elements and also
reverses the order of the int elements in every element of L.
It does not return anything.
"""
for i in reversed(L):
print(i)
In the above example, my code will simply print [5,6,7], [3,4], [1,2], which I am not trying to execute. This simply reverses the order of the lists, not the actual elements in the lists.
What should I add to the code so that it also changes the order of elements in the sublist?
[ EDIT: ; , , .]