fork download
  1. import re
  2.  
  3. input = r"""hello this is a car
  4. <hamburguer>this car is very good<\hamburguer>I want to fill this rules
  5. this pencil is red and very good, the movie was very fine
  6. <red>the color is blue and green<\red>
  7. <blue>your favorite color is the yellow<\blue>you want this<red>my smartphone is very expensive<\red>"""
  8.  
  9. lst = {}
  10. for item in re.finditer(r'<([^>]+)>([^>]+)<\\\1>', input):
  11. lst.setdefault('<%s>' % item.group(1),[]).append(item.group(2))
  12.  
  13. print(lst)
Success #stdin #stdout 0.04s 64988KB
stdin
Standard input is empty
stdout
{'<hamburguer>': ['this car is very good'], '<red>': ['the color is blue and green', 'my smartphone is very expensive'], '<blue>': ['your favorite color is the yellow']}