If you have a list of lists such as:
lst = [[8, 4], [10,2]]
How do you sort it such that the lst is:
lst = [[4, 8], [2,10]]
I have tried:
lst = [i.sort() for i in lst]
and:
lst = list(map(lambda x: x.sort(), lst))
but these just return a list with None.
Any help would be much appreciated!
>Solution :
i.sort() sorts the list in-place and returns None. Instead, you use sorted():
lst = [sorted(i) for i in lst]
Or a for loop:
for i in lst:
i.sort()