Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list.sort() returning None
#3
There is no mention in the Documentation, that this method return a None.
But, it returns None and sorts the list in-place.

I guess the expectation comes from str. The str methods always return a new str, because str is immutable.

If the original order is also required, then use sorted. If you don't care about the previous order, just use the sort method of the list instance. But do not assign the result to the name. Then the name refers to None and the list instance disappears after the garbage collector has done its work.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
list.sort() returning None - by SmallCoder14 - Mar-17-2024, 10:53 PM
RE: list.sort() returning None - by perfringo - Mar-18-2024, 05:48 AM
RE: list.sort() returning None - by DeaD_EyE - Mar-18-2024, 10:20 AM
RE: list.sort() returning None - by Pedroski55 - Mar-18-2024, 10:39 AM
RE: list.sort() returning None - by DeaD_EyE - Mar-18-2024, 08:16 PM
RE: list.sort() returning None - by SmallCoder14 - Mar-18-2024, 06:27 PM
RE: list.sort() returning None - by deanhystad - Mar-18-2024, 07:57 PM
RE: list.sort() returning None - by Pedroski55 - Mar-19-2024, 03:46 PM
RE: list.sort() returning None - by SmallCoder14 - Mar-19-2024, 09:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 744 Apr-29-2024, 04:38 PM
Last Post: Calab
  returning a List of Lists nafshar 3 1,183 Oct-28-2022, 06:28 PM
Last Post: deanhystad
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,403 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  list sort() function bring backs None CompleteNewb 6 4,322 Mar-26-2022, 03:34 AM
Last Post: Larz60+
  [solved] Sort list paul18fr 5 2,991 Aug-18-2021, 06:34 AM
Last Post: naughtyCat
  Sort List of Lists by Column Nju 1 13,748 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  How to sort os.walk list? Denial 6 11,970 Oct-10-2020, 05:28 AM
Last Post: Denial
  2d List not returning DariusKsm 2 1,793 Sep-22-2020, 05:11 PM
Last Post: DariusKsm
  Need help returning min() value of list? edwdas 3 2,160 Nov-10-2019, 09:43 PM
Last Post: snippsat
  Converting to a list and sort tantony 6 3,362 Oct-07-2019, 03:30 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020