fork(2) download
  1. def isNum(x):
  2. return x.isdigit()
  3.  
  4. input = raw_input().split(' ')
  5. output = set()
  6. right = 'x'
  7. for i in xrange(len(input) - 1, -1, -1):
  8. if not isNum(input[i]):
  9. right = 'x'
  10. elif right == 'x':
  11. right = input[i]
  12. elif input[i] != right:
  13. output.add((input[i], right))
  14.  
  15. print output
Success #stdin #stdout 0.01s 7732KB
stdin
1 2 3 x
stdout
set([('2', '3'), ('1', '3')])