Python Forum
HELP!!! string logical sorting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP!!! string logical sorting
#11
The sorted function and the sort method of lists takes a key argument.

If the argument is not given, the function/method compares object for object.
If a function is given as argument for key, then this function is called for each element and the return value of the key-function is used for comparison. This let you program easily custom sorters.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#12
@Gribouillis
Quote:Strings are not ignored, but 'foo' and 'foo' compare equal.
now understand,
thank you,
i give you a reputation point
Reply
#13
@DeaD_EyE
your answer is right, but I am sorry if I was rude, your answer is hard to understand,
thank you,
I give you a reputation as well
Reply
#14
As a addition tips natsort also called human sort🧬,works fine for most of these cases.
>>> from natsort import natsorted
>>> 
>>> thelist = ["t9","t8","t11","t10"]
>>> natsorted(thelist)
['t8', 't9', 't10', 't11']
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with Logical error processing List of strings dmc8300 3 1,418 Nov-27-2022, 04:10 PM
Last Post: Larz60+
  Greedy algorithms on logical problems Opensourcehacker 0 1,781 Nov-22-2020, 05:12 PM
Last Post: Opensourcehacker
  Unable to bit shift and logical OR bytes and ints? MysticLord 7 8,024 Sep-01-2020, 03:31 PM
Last Post: deanhystad
  Basic logical errors cpopescu 3 2,420 Jun-03-2020, 11:30 AM
Last Post: menator01
  Python logical operator AND rasec70 4 3,001 May-07-2020, 03:40 PM
Last Post: pyzyx3qwerty
  parsing logical expression with pyparsing palo173 2 5,951 May-13-2019, 09:22 AM
Last Post: palo173
  Sorting a copied list is also sorting the original list ? SN_YAZER 3 3,804 Apr-11-2019, 05:10 PM
Last Post: SN_YAZER
  Sorting list of lists with string and int Otbredbaron 6 4,738 May-07-2018, 06:04 AM
Last Post: buran

Forum Jump:

User Panel Messages

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