Python Forum
Human Sorting (natsort) does not work [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Human Sorting (natsort) does not work [SOLVED]
#3
(Jul-04-2022, 09:56 AM)snippsat Wrote: For sorting pathlib object add key=str.
Test.
from pathlib import Path
from natsort import natsorted, humansorted
from pprint import pprint

outputs = Path(r'G:\div_code\answer\sort_test')
search = "*.txt"
sorted_outputs = humansorted(outputs.glob(search), key=str)
pprint(sorted_outputs)
Output:
[WindowsPath('G:/div_code/answer/sort_test/file_1.txt'), WindowsPath('G:/div_code/answer/sort_test/file_2.txt'), WindowsPath('G:/div_code/answer/sort_test/file_3.txt'), WindowsPath('G:/div_code/answer/sort_test/file_10.txt'), WindowsPath('G:/div_code/answer/sort_test/file_11.txt'), WindowsPath('G:/div_code/answer/sort_test/file_33.txt')]

Ah thank you. That worked fine. Thumbs Up
Reply


Messages In This Thread
RE: Human Sorting (natsort) does not work - by AlphaInc - Jul-04-2022, 10:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sorting and Merging text-files [SOLVED] AlphaInc 10 7,899 Aug-20-2021, 05:42 PM
Last Post: snippsat
  sorting alphanumeric values in a human way idiotonboarding 3 3,951 Jan-22-2021, 05:57 PM
Last Post: idiotonboarding
  Sorting a copied list is also sorting the original list ? SN_YAZER 3 5,639 Apr-11-2019, 05:10 PM
Last Post: SN_YAZER
  How to convert Python crawled Bing web page content to human readable? dalaludidu 4 4,381 Sep-02-2018, 04:15 PM
Last Post: dalaludidu
  Batch job from epoch to human time jheeman 6 5,770 Feb-27-2018, 10:53 PM
Last Post: jheeman
  Time Difference in Epoch Microseconds then convert to human readable firesh 4 13,839 Feb-27-2018, 09:08 AM
Last Post: firesh

Forum Jump:

User Panel Messages

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