fork download
  1. import re
  2.  
  3. def findDimensions(text):
  4. return tuple([ float(n) for n in re.sub('[^0-9,.]', ' ', text ).replace(',', '.').split()])
  5.  
  6. print(findDimensions("14,5 x 55 x 22,0"))
  7. print(findDimensions("14,5 x 55cm x 22"))
  8. print(findDimensions("14,5cm x 55 x 22cm"))
  9. print(findDimensions("14,5cmx55x22cm"))
  10. print(findDimensions("14,5 cmx55 cmx22 cm"))
  11. print(findDimensions("14,5 cm x 55.0 x 22.0 cm"))
  12.  
  13.  
  14.  
Success #stdin #stdout 0.04s 9612KB
stdin
Standard input is empty
stdout
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)