Sorting two dimensional lists in Python

preview_player
Показать описание
How to sort 2d list by the second or third sub item in a lists. Great for making high score tables.
Рекомендации по теме
Комментарии
Автор

"Don't worry about how it works, just know it works" Do not just encourage copy and paste, you should explain how it is working so people fully grasp it instead of just copy and paste. It doesn't take too long to explain lambda its a simple function that I just read about literally 2 minutes ago.

connorhoskin
Автор

Thank you, it really helped. But you could have also done "people.sort(key = lambda x: x[1], reverse = True)" instead of reversing it again on the next line just to make it simpler and succinct.

shrijanaryal
Автор

I have a problem, I have a 2D list and the biggest score is 10000 and the score board is in descending order. After I have used the built in function, The value 10000 have been moved down to the bottom of the score board. I need some help ;-;
Note: I have also used the reverse() function

tang_kobe
Автор

Best explanation on sorting 2D lists I've seen. What about if you wanted to just print the scores of one person, by using their name rather than their index number? (say if it was a user defined selection and they wouldn't know the index number. With dictionaries you can use get, but you can't with lists.

riverkey
Автор

Great video. How could I add up each of the ages and print a total?

uddinna
Автор

Could you explain after having sorted the scores in rank order, what code is used to only display the top 3 highest scores instead of showing all the records? Thanks in advance

jsllsj
Автор

dude, explain the reason behind it. You are just promoting us to copy and past.

Hetp