+ 1

2D Sorted Array

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

21st Nov 2018, 5:34 PM
Gabriel Georges
Gabriel Georges - avatar
3 Réponses
+ 2
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
21st Nov 2018, 6:30 PM
Kieran Flaherty
Kieran Flaherty - avatar
+ 1
Could you provide an example of what you're trying to do?
21st Nov 2018, 5:40 PM
Just A Rather Ridiculously Long Username
+ 1
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
21st Nov 2018, 5:47 PM
Gabriel Georges
Gabriel Georges - avatar