Linked Questions
243 questions linked to/from Is there a built in function for string natural sort?
175 votes
1 answer
177k views
How to correctly sort a string with a number inside? [duplicate]
I have a list of strings containing numbers and I cannot find a good way to sort them. For example I get something like this: something1 something12 something17 something2 something25 something29 ...
84 votes
3 answers
170k views
Sort filenames in directory in ascending order [duplicate]
I have a directory with jpgs and other files in it, the jpgs all have filenames with numbers in them. Some may have additional strings in the filename. For example. 01.jpg Or it could be Picture 03....
23 votes
3 answers
23k views
Python analog of PHP's natsort function (sort a list using a "natural order" algorithm) [duplicate]
I would like to know if there is something similar to PHP natsort function in Python? l = ['image1.jpg', 'image15.jpg', 'image12.jpg', 'image3.jpg'] l.sort() gives: ['image1.jpg', 'image12.jpg', '...
4 votes
1 answer
12k views
ordered with glob.glob in python [duplicate]
I have a list of file: foo_00.txt foo_01.txt foo_02.txt foo_03.txt foo_04.txt foo_05.txt foo_06.txt foo_07.txt foo_08.txt foo_09.txt foo_10.txt foo_11.txt ......... ......... foo_100.txt foo_101.txt ...
8 votes
2 answers
14k views
Ordered os.listdir() in python [duplicate]
How to add files into a list by order In my directory i have the following files: slide1.xml, slide2.xml, slide3.xml ... slide13.xml os.listdir(path) doesn't return me a list by order I've tried ...
7 votes
1 answer
19k views
Read files sequentially in order [duplicate]
I have a number of files in a folder with names following the convention: 0.1.txt, 0.15.txt, 0.2.txt, 0.25.txt, 0.3.txt, ... I need to read them one by one and manipulate the data inside them. ...
0 votes
2 answers
12k views
How to sort files by number in filename of a directory? [duplicate]
I have a directory containing a lot of textfiles named in a specific order: 0.txt 1.txt 2.txt .... 100.txt 101.txt ..... 40000.txt When im trying to retrieve a sorted list of all the files im using: ...
5 votes
3 answers
27k views
Python sorting list with negative number [duplicate]
In attempt to learn python by practicing, I am trying to implement and test out quick sort algorithm using python. The implementation itself was not difficult, however the result of the sort is ...
5 votes
1 answer
12k views
Python: Sort a list of strings composed of letters and numbers [duplicate]
I have a list that its elements are composed of a letters and numbers as shown below : ['H1', 'H100', 'H10', 'H3', 'H2', 'H6', 'H11', 'H50', 'H5', 'H99', 'H8'] I wanted to sort it, so I used the ...
3 votes
4 answers
1k views
need help with sort function in python [duplicate]
The contents of my dictionary is like so:- >>> dict {'6279': '45', '15752': '47', '5231': '30', '475': '40'} I tried using the sort function on the keys. I noticed that the sort function ...
4 votes
3 answers
11k views
How do you sort the contents of a .txt file in numerical order? [duplicate]
I have some trouble making a code that arranges a .txt file in numerical order. The problem I'm having is when ordering numbers 77, 45, 85, 100 in the .txt file it orders it as 100, 45, 77, 85; 100 ...
2 votes
4 answers
4k views
Python - Human sort of numbers with alpha numeric, but in pyQt and a __lt__ operator [duplicate]
I have data rows and wish to have them presented as follows: 1 1a 1a2 2 3 9 9.9 10 10a 11 100 100ab ab aB AB As I am using pyQt and code is contained within a TreeWidgetItem, the code I'm trying to ...
2 votes
2 answers
6k views
Python Sorted By Name [duplicate]
I tried to sort using sorted dir =["A1","A2","A10","A3"] sorted(dir) My expected array is ["A1","A2","A3","A10"] but actual result is ["A1", "A10", "A2", "A3"] How to sort array by name in python ?
3 votes
2 answers
2k views
Sorting dictionary with alphanumeric keys in natural order [duplicate]
I have a python dictionary: d = {'a1': 123, 'a2': 2, 'a10': 333, 'a11': 4456} When I sort the dictionary using OrderedDict I get the following output: from collections import OrderedDict OrderedDict(...
1 vote
3 answers
4k views
How do I preserve the order of images while creating video in python [duplicate]
I need to create a video out of sequence of images in python. I found this code online that works fine but I am having a small problem with the ordering of the images when being read in python. Even ...