I have a multidimensional list which is basically a list of strings nested within a list. I want a list to be reversed and also the list items within the list to be reverse and further the strings in the list should also be reversed.
Ex: I have a list
[
['123', '456', '789'],
['234', '567', '890'],
['345', '678', '901']
]
I want the result to be
[
['109', '876', '543'],
['098', '765', '432'],
['987', '654', '321']
]
I've already tried the code, It's working. But can we simplify further using list comprehension.
Below is the code which I tried.
old = [['123', '456', '789'], ['234', '567', '890'], ['345', '678', '901']]
new = [];
for x in old[::-1]:
z = [];
for y in x:
z.insert(0, y[::-1])
new.append(z)
print(new)
Input
[['123', '456', '789'], ['234', '567', '890'], ['345', '678', '901']]
Output
[['109', '876', '543'], ['098', '765', '432'], ['987', '654', '321']]