list.sort
sorts the list in place, i.e. it doesn’t return a new list. Just write
newList.sort()
return newList
The above answer is goden as performing return list.sort()
bytes me often, because Python is usually an environment using the functional approach.
Answer from [WayBack] python – Why does “return list.sort()” return None, not the list? – Stack Overflow
Background information:
- [WayBack] 5. Data Structures — Python 2.7.15 documentation:
list.sort()
list.
sort
(cmp=None, key=None, reverse=False)- Sort the items of the list in place (the arguments can be used for sort customization, see
sorted()
for their explanation).
- [WayBack] 5. Data Structures — Python 3.7.1rc1 documentation:
list.sort()
list.
sort
(key=None, reverse=False)- Sort the items of the list in place (the arguments can be used for sort customization, see
sorted()
for their explanation).
–jeroen