Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sort all lists within a list

If you have a list of lists such as:

lst = [[8, 4], [10,2]]

How do you sort it such that the lst is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading