fork download
  1. import re,ast
  2.  
  3. file_list = ['15L-0.3', '16L-0.4_redo', '15L-0', '16L-redo']
  4. rx = re.compile(r'^(\d+)L(?:-(\d+(?:\.\d+)?))?([_-].*)?$')
  5. array = []
  6. for i in file_list:
  7. m = rx.search(i)
  8. if m:
  9. arr = list(m.groups())
  10. arr[0] = int(arr[0]) # This is an int
  11. if arr[1]: # If Group 2 matched, it is either a doat or int float
  12. arr[1] = ast.literal_eval(arr[1]) # Parse the second number as int or float
  13. array.append([x for x in arr if x is not None]) # Remove any None values
  14.  
  15. print (array)
  16.  
Success #stdin #stdout 0.03s 10016KB
stdin
Standard input is empty
stdout
[[15, 0.3], [16, 0.4, '_redo'], [15, 0], [16, '-redo']]