Python Forum
a.sort() == b.sort() all the time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a.sort() == b.sort() all the time
#2
When a is a list, a.sort() sorts the list in place, but the call to a.sort() returns None
>>> a = [1, 8, 4, 2]
>>> a.sort()
>>> a
[1, 2, 4, 8]
>>> a.sort() is None
True
Hence you are testing None == None, which always returns True.
Reply


Messages In This Thread
a.sort() == b.sort() all the time - by 3lnyn0 - Apr-19-2022, 06:22 PM
RE: a.sort() == b.sort() all the time - by Gribouillis - Apr-19-2022, 06:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Filer and sort files by modification time in a directory tester_V 5 373 May-02-2024, 05:39 PM
Last Post: tester_V
  Sort a list of dictionaries by the only dictionary key Calab 2 672 Apr-29-2024, 04:38 PM
Last Post: Calab
  list.sort() returning None SmallCoder14 8 683 Mar-19-2024, 09:49 PM
Last Post: SmallCoder14
  sort search results by similarity of characters jacksfrustration 5 483 Feb-16-2024, 11:59 PM
Last Post: deanhystad
  How to sort .csv file test log which item first fail and paint color SamLiu 24 5,159 Sep-03-2022, 07:32 AM
Last Post: Pedroski55
  'dict_items' object has no attribute 'sort' Calli 6 4,653 Jul-29-2022, 09:19 PM
Last Post: Gribouillis
  Sort Differences in 2.7 and 3.10 Explained dgrunwal 2 1,404 Apr-27-2022, 02:50 AM
Last Post: deanhystad
  list sort() function bring backs None CompleteNewb 6 4,221 Mar-26-2022, 03:34 AM
Last Post: Larz60+
  How to perform DESC table sort on dates stored as TEXT type. hammer 7 2,284 Mar-15-2022, 01:10 PM
Last Post: hammer
  [solved] Sort list paul18fr 5 2,954 Aug-18-2021, 06:34 AM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

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