I’m a Python beginner so I apologise in advance if my question may be obvious.
I have a list called EVENTS that contains lists of information on ‘timing’,’side’ and ‘labels’. I have recreated a simpler version of the one I am using here:
EVENTS = [ [2.55800009, 1.88999999],['Left', 'Left'], ['Foot Strike', 'Foot Off']]
I would like to sort the list such that the ‘timing’ is sorted in order of ascence, but so that the strings ‘side’ and ‘label’ would follow that order.
so the sorted list should be:
EVENTS_SORTED = [ [1.88999999, 2.55800009],['Left', 'Left'], ['Foot Off', 'Foot Strike']]
I have tried
EVENTS_SORTED = sorted(EVENTS,key=lambda x:(x[0]))
EVENTS_SORTED = sorted(EVENTS,key=operator.itemgetter(0))
Where I get the error
'<' not supported between instances of 'str' and 'float'
I understand that the approach I am using is thus not applicable to the list I have but I am not entirely sure why.
Any help on a better approach – or a better way to structure the data to make this step easier – would be greatly appreciated
IVM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.