fork download
  1. import re
  2.  
  3. line = raw_input()
  4.  
  5. answer = []
  6.  
  7. for block in re.findall(r'[\d+ ]+\D+', line):
  8. seq = block.split()[:-1]
  9. second = seq[-1]
  10. for first in seq[:-1]:
  11. if first != second:
  12. answer.append((first, second))
  13.  
  14. for tup in set(answer):
  15. print tup
  16.  
Success #stdin #stdout 0.01s 7732KB
stdin
0 14 887 3 x 2 y 4 4 3 a 1 1 8 4 3 b 1 2 3 1 2 3 c
stdout
('0', '3')
('2', '3')
('8', '3')
('887', '3')
('14', '3')
('4', '3')
('1', '3')