Concatenating files in order

Tim Chase python.list at tim.thechases.com
Tue May 23 22:36:22 EDT 2017


On 2017-05-23 13:38, woooee at 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





More information about the Python-list mailing list