fork download
  1. import re
  2.  
  3.  
  4. def magic(value):
  5. parts = re.split(r'(\d+)', value)
  6. return [int(part) if part.isdigit() else part for part in parts]
  7.  
  8.  
  9. a = [
  10. ['c2sp1s5', 0],
  11. ['c2sp1s10', 1],
  12. ['c2sp1s11', 0],
  13. ['c2sp1s1', 0]
  14. ]
  15.  
  16. print( sorted(a, key=lambda v: magic(v[0])) )
Success #stdin #stdout 0.02s 6852KB
stdin
Standard input is empty
stdout
[['c2sp1s1', 0], ['c2sp1s5', 0], ['c2sp1s10', 1], ['c2sp1s11', 0]]