Posted By

AsTeR on 07/28/11


Tagged

python regexp re sorting


Versions (?)

Python


 / Published in: Python
 

Sorting strings in an array like : "toto-2.csv", "toto-4.csv", "toto-12.csv" and "toto-101.csv".

  1. #Sorting strings in an array like
  2. filePaths = ["toto-2.csv", "toto-4.csv", "toto-12.csv" and "toto-101.csv"]
  3. keyfunction = lambda filePath : int(re.findall('(\d*)\.csv', filePath)[0])
  4. filePaths.sort(key=keyfunction)

Report this snippet  

You need to login to post a comment.