How do I sort the below list of tuples by the second element?
[('8B', u'11'), ('8P', u'2.3'), ('8C', u'1.6')]
Expected Result would be:
[('8C', u'1.6'), ('8P', u'2.3'), ('8B', u'11')]
How do I sort the below list of tuples by the second element?
[('8B', u'11'), ('8P', u'2.3'), ('8C', u'1.6')]
Expected Result would be:
[('8C', u'1.6'), ('8P', u'2.3'), ('8B', u'11')]
Tested and confirmed in Python IDLE
my_list = [('8B', u'11'), ('8P', u'2.3'), ('8C', u'1.6')]
my_list.sort(key=lambda x: float(x[1]))
print(my_list)
Got
[('8C', '1.6'), ('8P', '2.3'), ('8B', '11')]