.sort() and .reverse() change the list in place and return None See the documentation for the mutable sequence :
The sort() and reverse() methods modify the list to save space when sorting or changing a large list. To remind you that they work by side effect, they do not return a sorted or inverted list.
Do this instead:
a.sort() print(a) a.reverse() print(a)
or use sorted() and reversed() functions.
print(sorted(a))
These methods return a new list and leave the original input list intact.
Demo, sorting and reversal in place:
>>> a = [66.25, 333, 333, 1, 1234.5] >>> a.sort() >>> print(a) [1, 66.25, 333, 333, 1234.5] >>> a.reverse() >>> print(a) [1234.5, 333, 333, 66.25, 1]
And creating new sorted and inverted lists:
>>> a = [66.25, 333, 333, 1, 1234.5] >>> print(sorted(a)) [1, 66.25, 333, 333, 1234.5] >>> print(list(reversed(a))) [1234.5, 1, 333, 333, 66.25] >>> print(a[::-1]) [1234.5, 1, 333, 333, 66.25] >>> print(sorted(a, reverse=True)) [1234.5, 333, 333, 66.25, 1] >>> a