xxxxxxxxxx
# list.sort sorts the list in place, i.e. it doesn't return a new list. Just write
newList.sort()
return newList
xxxxxxxxxx
# The problem is here:
answer = newList.sort()
# sort does not return the sorted list; rather, it sorts the list in place.
#Use:
answer = sorted(newList)
xxxxxxxxxx
because .sort() modifies the original list, so you can just do:
my_list = [6, 5, 4]
my_list.sort()
print(my_list)
xxxxxxxxxx
>>> xs = [None, 1, 3, None, 2]
>>> sorted(xs, key=lambda x: (x is None, x))
[1, 2, 3, None, None]
>>> sorted(xs, key=lambda x: (x is not None, x))
[None, None, 1, 2, 3]
>>> sorted(xs, key=lambda x: (x is None, x), reverse=True)
[None, None, 3, 2, 1]
>>> sorted(xs, key=lambda x: (x is not None, x), reverse=True)
[3, 2, 1, None, None]