On 2017-05-23 13:38, woo...@gmail.com wrote: > It is very straight forward; split on "_", create a new list of > lists that contains a sublist of [file ending as an integer, file > name], and sort > > fnames=["XXX_chunk_0", > "XXX_chunk_10", > "XXX_chunk_1", > "XXX_chunk_20", > "XXX_chunk_2"] > sorted_list=[[int(name.split("_")[-1]), name] for name in > fnames] print "before sorting", sorted_list > sorted_list.sort() > print "after sorting ", sorted_list
Which is great until you have a file named "XXX_chunk_header" and your int() call falls over ;-) -tkc -- https://mail.python.org/mailman/listinfo/python-list