fork(1) download
  1. import re
  2.  
  3. def tyre_details(tyre_size):
  4. pattern = r'(\d{3})/(\d{2})([A-Z]{1,2})(\d{2})'
  5. m = re.match(pattern, tyre_size)
  6. details = {}
  7. if m:
  8. width, profile, rating, rim = m.groups()
  9. details = {"width": int(width), "profile": int(profile), "rating": rating, "rim": int(rim)}
  10. return details
  11.  
  12. tyre_specs = '255/45W17'
  13. print( tyre_details(tyre_specs) )
Success #stdin #stdout 0.03s 9596KB
stdin
Standard input is empty
stdout
{'width': 255, 'profile': 45, 'rating': 'W', 'rim': 17}