fork download
  1. #! /usr/env/python3
  2.  
  3. from collections import Counter
  4.  
  5. text = '''2>4
  6. 1>2
  7. 2>3
  8. 3>5
  9. 3>1
  10. 1>4
  11. 4>2
  12. '''
  13.  
  14. def transform(s, number_map={}, count=Counter()):
  15. number = number_map.setdefault(s, len(number_map) + 1)
  16. count[number] += 1
  17. return str(number) + '.' + str(count[number])
  18.  
  19. for line in text.splitlines():
  20. left, right = line.split('>')
  21. print(transform(left) + '>' + transform(right))
  22.  
Success #stdin #stdout 0.02s 9048KB
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