I have a class:
class Prediction():
def __init__(self, l):
self.start = l[0]
self.end = l[1]
self.score = l[2]
And a list, where each element is a Prediction. It's aptly named predictions.
I want to sort predictions by the start attribute of the Prediction class.
Something like this:
predictions_start_order = sorted(predictions, key=start)
Which doesn't work. What am I missing?
predictions_start_order = sorted(predictions, key=lambda x: x.start)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With