Linked Questions
243 questions linked to/from Is there a built in function for string natural sort?
0 votes
2 answers
296 views
Python sorted order of files [duplicate]
I have written the following code for a program to display the image path names in a folder. However, as seen in the output, the pictures' paths are not being displayed in the correct order despite me ...
1 vote
2 answers
770 views
How to sort glob.glob containing numbers? [duplicate]
Doing glob.glob('/var/log/apache2/other_vhosts_access.log*') gives an unsorted list such as ['....76.gz', '....16.gz', '....46.gz', ...]. Also, sorted(glob.glob('/var/log/apache2/other_vhosts_access....
0 votes
2 answers
820 views
How to get os.listdir to list files in order [duplicate]
I'm wanting to rename all of the files in a directory. When sorted by name in Windows Explorer, they appear in the correct order: Cue 001 - 002.mp3 ... Cue 001 - 010.mp3 Cue 001 - 011.mp3 ... Cue 001 ...
0 votes
2 answers
131 views
Python: Sort a list so that 5.10 is after 5.9 [duplicate]
how would you sort a list of numbers like 5.1, 5.2, 5.3,... 5.10,5.11 in a way that doesn't put 5.10 and 5.11 after 5.1 in Python. I basically want python to realize that I don't actually mean 5.10 ...
3 votes
1 answer
225 views
python equivalent to php natcasesort [duplicate]
Possible Duplicate: Does Python have a built in function for string natural sort? Is there a function in python equivalent to php's natcasesort()? http://php.net/manual/en/function.natcasesort....
0 votes
2 answers
457 views
Python alphanumeric sorting for list of lists [duplicate]
I'm currently trying to sort a list of the form: [["Chr1", "949699", "949700"],["Chr11", "3219", "444949"], ["Chr10", "699", "800"],["Chr2", "232342", "235345234"], ["ChrX", "4567", "45634"],["Chr1", ...
0 votes
1 answer
444 views
List ordering with os.listdir - appending files in order [duplicate]
I have a folder of fits files that are all labelled img_1.fits, img_32.fits, img_2.fits ... etc and I want to iterate through them in numerical order and append the data to an array however I cannot ...
1 vote
1 answer
219 views
Python sort files by filename with numbers as first letters [duplicate]
I have the following list which is the output of mylist.sort() ['0_sound.wav', '10_sound.wav', '15_sound.wav', '20_sound.wav', '5_sound.wav'] This makes sense, since the filenames are treated as ...
1 vote
3 answers
104 views
Sorting list of strings by substring [duplicate]
I need to sort this list list = ['16. Michlík', '4. and 65. Bichakhchyan', '15. Pavol'] according to first number of each string. So that output should look like this list = ['4. and 65. ...
1 vote
3 answers
221 views
Why does sorted() put 9 after 84 and 878? [duplicate]
numbers = ['3','1','6','5','4','4','3','2','1','4','3','5','4','9','84','7','878','6'] counts = dict() for number in numbers: counts[number] = counts.get(number, 0) + 1 print counts for k,v in ...
2 votes
4 answers
189 views
How to sort a dictionary by key in python [duplicate]
I have a python dictionary named data and have sub dictionaries inside it, such as data = {'ind1' : {}, 'ind10' : {}, 'ind11' : {}, 'ind12' : {}, 'ind13', 'ind14' : {}, 'ind15' : {}, 'ind16' : {}, '...
1 vote
3 answers
122 views
Sorting list by string pattern [duplicate]
I have a list of files that looks something like this: listOfFiles = ['XLOG100.LOG', 'XLOG101.LOG', 'XLOG102.LOG', 'XLOG103.LOG', 'XLOG104.LOG', 'XLOG105.LOG', 'XLOG106.LOG', 'XLOG107.LOG', 'XLOG108....
0 votes
0 answers
298 views
How to sort a list of numbers that with fixed prefix? [duplicate]
I have a list of ['rs12345','rs21','rs55189']; I need to sort them as numbers after strip the prefix 'rs'. How can I do it in Python ? # row.keys() is ['rs12345','rs21','rs55189'] fieldnames = sorted(...
0 votes
1 answer
113 views
python sort alphanumeric list without ordereddict [duplicate]
I've read many similar questions, but none of the solutions match the requirements I need which is, using Python 2.6.6 and without installing or using OrderedDict, how can I get my list to sort based ...
0 votes
3 answers
95 views
How to sort python list by numbers? [duplicate]
I would like to sort the following list by numbers : x = ('a-34','a-1','a-0', 'a-11', 'a-2') y = sorted(x) print(y) This produces : ['a-0', 'a-1', 'a-11', 'a-2', 'a-34'] But I need : ['a-0', 'a-1', '...