Python Forum
sorting alphanumeric values in a human way
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sorting alphanumeric values in a human way
#1
So simple question, I could make it work in a lambda probably but my experience is limited and I suspect there may already be a built in to do what I need. I have some data that I currently sort using sort like so

data.sort(order=['bin','ref'])

I'm not the one who uses the data, so i am only just finding out it only really works 80% of the time. 'bin' is always an integer, so the sort works great, and that's the critical value. sorting by ref is where it breaks down, as 'ref' is alphanumeric which leaves us to a bad order. ref values are of the format 'A1', 'A4', 'A13', which means when sorted 'A13' comes before 'A4', which is not the desired behavior. is there a built in sort option to do a windows style alphabetic sort, instead of a linux style? or do i need to manually mangle the string and split and sort it that way?

I always prefer to use a built in w/ options than roll my own, because one will always be less buggy than the other, and it's not my code lol
Reply


Messages In This Thread
sorting alphanumeric values in a human way - by idiotonboarding - Jan-22-2021, 04:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Human Sorting (natsort) does not work [SOLVED] AlphaInc 2 1,150 Jul-04-2022, 10:21 AM
Last Post: AlphaInc
  Sorting numerical values provided by QAbstractTableModel BigMan 0 1,375 Jun-04-2022, 12:32 AM
Last Post: BigMan
  List sort - alphanumeric? papsphilip 2 2,472 Oct-05-2019, 09:27 PM
Last Post: papsphilip
  Sorting a copied list is also sorting the original list ? SN_YAZER 3 3,081 Apr-11-2019, 05:10 PM
Last Post: SN_YAZER
  How to convert Python crawled Bing web page content to human readable? dalaludidu 4 3,431 Sep-02-2018, 04:15 PM
Last Post: dalaludidu
  Batch job from epoch to human time jheeman 6 4,550 Feb-27-2018, 10:53 PM
Last Post: jheeman
  Time Difference in Epoch Microseconds then convert to human readable firesh 4 11,649 Feb-27-2018, 09:08 AM
Last Post: firesh
  Sorting values calculated in python stumunro 4 3,984 Sep-13-2017, 06:09 AM
Last Post: nilamo
  sorting nested dict according to values merlem 6 17,636 Apr-01-2017, 10:01 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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