fork download
  1. import re
  2. text = "This is the first line of the file.\nhere we tell you to make a tea.\n\nstep 1\n\nPour more than enough water for a cup of tea into a regular pot, and bring it to a boil.\n\nstep \n2\n\nThis will prevent the steeping water from dropping in temperature as soon as it is poured in.\n\nstep 3 \n\n\nWhen using tea bags, the measuring has already been done for you - generally it's one tea bag per cup."
  3. results = re.findall(r'^step\s*(\d+)\s*(.*?)\s*(?=^step\s*\d|\Z)', text, re.DOTALL | re.MULTILINE)
  4. print(dict([("step{}".format(x),y) for x,y in results]))
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
{'step2': 'This will prevent the steeping water from dropping in temperature as soon as it is poured in.', 'step1': 'Pour more than enough water for a cup of tea into a regular pot, and bring it to a boil.', 'step3': "When using tea bags, the measuring has already been done for you - generally it's one tea bag per cup."}