fork download
  1. import re
  2.  
  3. line = "23.3(14) 600(3) 760.35(10)"
  4.  
  5. # split the items
  6. rx = re.compile(r"\d[\d().]+")
  7. digits = rx.findall(line)
  8.  
  9. # determine the length
  10. def countandsplit(x):
  11. ''' Finds the length and returns new values'''
  12. a = x.find('(')
  13. b = x.find('.')
  14. if a != -1 and b != -1:
  15. length = a-b-1
  16. else:
  17. length = 0
  18.  
  19. parts = list(filter(None, re.split(r'[()]', x)))
  20. number1 = float(parts[0])
  21. number2 = round(float(parts[1]) * 10 ** -length, length)
  22. return [number1, number2]
  23.  
  24. result = [x for d in digits for x in countandsplit(d)]
  25. print(result)
  26.  
Success #stdin #stdout 0.03s 9984KB
stdin
Standard input is empty
stdout
[23.3, 1.4, 600.0, 3.0, 760.35, 0.1]