2D Sorted Array | Sololearn: Learn to code for FREE!


2D Sorted Array

How do we make a 2D Sorted Array in Python? I need it for a database system, any help?

11/21/2018 5:34:52 PM

Gabriel Georges

3 Answers

New Answer


If I understand your question correctly, you want to sort the outer list by the first item in the inner list. Is that correct? Try: sorted(yourList, key=lambda x: x[0]) This will return a sorted version of yourList in ordered by the first item in the inner list in ascending order


Could you provide an example of what you're trying to do?


I want the code to sort it in a way that whichever list is smaller, goes in first, so as if, I already have a list in the database [100, "Name", "Gender" , 23] this is one list, I want it to be added to this list [[101, "Name", "Gender" , 27] [146, "Human" , "Male" , 46] [578, "Felicia" , "Female", 25]] I want the code to sort this list in a way that the first number is the indicator, the lower number is the first one, the biggest number is the last in the list