Answer the question
In order to leave comments, you need to log in
Why does sorting a list of tuples return None?
Good evening. Please tell me, for the second day I can not solve the problem, I have a list of tuples, they have certain values. I need to sort tuples by last element. Returns None when sorted. Why None? Thank you.
result = [('first', 3.0, 4.0, 5.0, 6.0, 6.0), ('second', 5.0, 6.0, 7.0, 9.0, 14.7), ('third', 10.0, 12.0, 16.0, 19.0, 59.92)]
print(result.sort(key=lambda x: x[5]))
Answer the question
In order to leave comments, you need to log in
Because the sort method modifies result and returns nothing. If you want to return a new sorted list without changing the original one, you should use the sorted function .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question