How to reverse the elements of all sub-list in a nested list with Python

1 Answer

0 votes
nestedlist = [[1, 2, 3], [1, 5], [6, 1, 8, 9, 10], [1, 9, 10, 10], [1]]

for sub_list in nestedlist:
    sub_list.reverse()

print(nestedlist)



'''
run:

[[3, 2, 1], [5, 1], [10, 9, 8, 1, 6], [10, 10, 9, 1], [1]]

'''

 



answered Feb 9, 2025 by avibootz
...