Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] Sort list
#1
Hi

I've been trapped by names I've been getting in a list; I spent some time in looking in internet to find a way; in the current example, I want that list index 1 correspond to 'Name_2' and not 'Name_10' (and so on, in ascending order)

Is there a basic instruction or should I need to split numbers from strings in order to sort?

Thanks for advices

Paul

MyList = ['Name_1', 'Name_10', 'Name_2', 'Name_20', 'Name_3', 'Name_32']
print(f"Initial = {MyList}")
print()
print(f"Test 1 = {sorted(MyList)}")
Reply


Messages In This Thread
[solved] Sort list - by paul18fr - Jul-09-2021, 05:21 PM
RE: Sort list - by deanhystad - Jul-09-2021, 05:44 PM
RE: Sort list - by ndc85430 - Jul-09-2021, 05:53 PM
RE: Sort list - by snippsat - Jul-09-2021, 07:34 PM
RE: [solved] Sort list - by paul18fr - Jul-10-2021, 10:05 AM
RE: [solved] Sort list - by naughtyCat - Aug-18-2021, 06:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  list.sort() returning None SmallCoder14 8 601 Mar-19-2024, 09:49 PM
Last Post: SmallCoder14
  [solved] list content check paul18fr 6 720 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  Sort a list of dictionaries by the only dictionary key Calab 1 501 Oct-27-2023, 03:03 PM
Last Post: buran
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,432 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  Loop through list of ip-addresses [SOLVED] AlphaInc 7 4,003 May-11-2022, 02:23 PM
Last Post: menator01
  [solved] Basic question on list matchiing paul18fr 7 1,875 May-02-2022, 01:03 PM
Last Post: DeaD_EyE
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,328 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  list sort() function bring backs None CompleteNewb 6 4,150 Mar-26-2022, 03:34 AM
Last Post: Larz60+
  Sort List of Lists by Column Nju 1 11,584 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  How to sort os.walk list? Denial 6 11,582 Oct-10-2020, 05:28 AM
Last Post: Denial

Forum Jump:

User Panel Messages

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