fork download
  1. import re
  2. inventory = ["shoes, 12, 29.99", "shirts, 20, 9.99", "sweatpants, 25, 15.00", "scarves, 13, 7.75"]
  3. pattern = "(?P<product>[a-z]+),\s(?P<quantity>[0-9]+),\s(?P<price>[0-9]*\.[0-9]{2})"
  4.  
  5. for items in inventory:
  6. details = re.match(pattern, items)
  7. print("The store has {quantity} {product}, each for {price} USD".format(**details.groupdict()))
Success #stdin #stdout 0.03s 9708KB
stdin
Standard input is empty
stdout
The store has 12 shoes, each for 29.99 USD
The store has 20 shirts, each for 9.99 USD
The store has 25 sweatpants, each for 15.00 USD
The store has 13 scarves, each for 7.75 USD