fork download
  1. import re
  2.  
  3.  
  4. def post_processing(text):
  5. pattern = re.compile(r"\b(\d+\s*\..*?)(\d+\s*\..*?)(\d+\s*\..*?)(?=\d+\.|$)", re.M)
  6. matches = pattern.finditer(text)
  7.  
  8. for _, match in enumerate(matches, start=1):
  9. result = [re.sub(r"(\d)\s+\.", r"\1.", s) for s in match.groups()]
  10. return " ".join(result)
  11.  
  12.  
  13. s = "Suggestions for restaurants:1 . Pizza2. Burger3. Sushi4. Noodles..."
  14. print(post_processing(s))
Success #stdin #stdout 0.03s 9656KB
stdin
Standard input is empty
stdout
1. Pizza 2. Burger 3. Sushi