Is there an easy way to sort a list within a list so that the values go from least to greatest or vice versa? I can so far only find information on ordering the lists themselves based off the leading value.
Here is an example:
data = [[8,7], [10,5,], [8,10]]
>> [[7,8], [5,10], [8,10]
Use a list comprehension to sort each element (each list object) in data:
data = [sorted(x) for x in data]
data is now:
[[7, 8], [5, 10], [8, 10]]
You could also do this:
map(sorted, data)
Then use list on that map object to actually turn it into a list...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With