Sort List of Tuples Containing Strings By First Element Float (Python)

Viewed 1877

I have a long list of tuples:

[...
(0.862, 'beehive', 'bug'),
(0.12, 'yard', 'property'),
(0.0, 'lake', 'mailbox'),
(0.37, 'maintenance', 'shears'),
(0.1666, 'summer', 'popsicle'),
(0.9, 'poplar', 'tree')
...]

and I need to sort this list descending by the float values. I know the Python automatically sorts lists by the first value, however even when I call sorted or even explicitly specify the first element, I haven't had success.

sorted(mylist) # doesn't sort the list at all

sorted(mylist, key = x[0]) # on this sort attempt I get "'str' object is not callable"

Can anyone provide detail as to why the list is still disorganized despite these sorting attempts and what might sort by floats in descending order?

2 Answers
Related