Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list.sort() returning None
#6
In this code:
print(articles_upvotes.sort())
sort changes the order of objects in articles_upvotes and returns None. The print command does not print articles_upvotes, it prints the value returned by articles_upvotes.sort().

You can fix this by printing articles_upvotes like this:
articles_upvotes.sort()
print(articles_upvotes)
Or you can use sorted that returns a sorted copy of articles_upvotes. articles_upvotes is unchanged.
print(sorted(articles_upvotes))
All functions return a value. Often the returned value is None. You should read the documentation and look to see what value is returned. If the return value isn't mentioned, it is probably None.
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 690 Apr-29-2024, 04:38 PM
Last Post: Calab
  returning a List of Lists nafshar 3 1,145 Oct-28-2022, 06:28 PM
Last Post: deanhystad
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,373 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  list sort() function bring backs None CompleteNewb 6 4,257 Mar-26-2022, 03:34 AM
Last Post: Larz60+
  [solved] Sort list paul18fr 5 2,970 Aug-18-2021, 06:34 AM
Last Post: naughtyCat
  Sort List of Lists by Column Nju 1 12,982 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  How to sort os.walk list? Denial 6 11,847 Oct-10-2020, 05:28 AM
Last Post: Denial
  2d List not returning DariusKsm 2 1,749 Sep-22-2020, 05:11 PM
Last Post: DariusKsm
  Need help returning min() value of list? edwdas 3 2,143 Nov-10-2019, 09:43 PM
Last Post: snippsat
  Converting to a list and sort tantony 6 3,329 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