Might be a silly question but taking a course we just talked about lambda and how it can be used. One of our exercises was to sort a list based on second number in tuples. Example list:
a = [(0, 2), (4, 3), (9, 9), (10, -1)]
Sort based on the numbers 2, 3, 9, and -1 for an expected result of:
[(10, -1), (0, 2), (4, 3), (9, 9)]
My code was the following:
print(a.sort(key=lambda num: num[1]))
The correct answer is:
a.sort(key=lambda x: x[1])
print(a)
Seeing how I essentially had the same answer, this leads me to think I had the order of operations incorrect somewhere. The output of my code was "None" and the output of the correct answer is the expected result above.
What am I missing here? Is there another way to do it correctly?