How would I sort a list of Tuples in Python. For example, I have:
aList = [ ( 'person', 20, 100 ), ( 'cat', 30, 900 ), ( 'dog', 5, 500 ) ]
So I want to sort the Tuples using their third values (100, 900, and 500) I would get:
aList = [ ( 'cat', 30, 900 ), ( 'dog', 5, 500 ), ( 'person', 20, 100 ) ]
When I use the answer from the duplicate question I get the same values back:
data = [ ( 'person', 20, 100 ), ( 'cat', 30, 900 ), ( 'dog', 5, 500 ) ]
def sorted_by_second():
sorted(data, key=lambda tup: tup[1])
return data
sorted_by_second()
and I get:
[('person', 20, 100), ('cat', 30, 900), ('dog', 5, 500)]