[Python] 怎麼排序複雜資料?




>>> student_tuples = [
(‘john’, ‘A’, 15),
(‘jane’, ‘B’, 12),
(‘dave’, ‘B’, 10),
]
>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
[(‘dave’, ‘B’, 10), (‘jane’, ‘B’, 12), (‘john’, ‘A’, 15)]

參考資料:




Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.