fork download
  1. #! python3
  2.  
  3. text = """
  4. 2>4
  5. 1>2
  6. 2>3
  7. 3>5
  8. 3>1
  9. 1>4
  10. 4>2
  11. """
  12.  
  13. import re
  14. tokens = re.split(r"\s+|>", text.strip())
  15.  
  16. id = {}
  17. count = {}
  18. out = []
  19. for token in tokens:
  20. if token not in id:
  21. id[token] = len(id) + 1
  22. count[token] = 1
  23. else:
  24. count[token] += 1
  25. out.append((id[token], count[token]))
  26.  
  27. for i in range(0, len(out), 2):
  28. print("{}.{}>{}.{}".format(out[i][0], out[i][1], out[i + 1][0], out[i + 1][1]))
  29.  
Success #stdin #stdout 0.02s 8736KB
stdin
Standard input is empty
stdout
1.1>2.1
3.1>1.2
1.3>4.1
4.2>5.1
4.3>3.2
3.3>2.2
2.3>1.4