fork download
  1. from collections import Counter
  2.  
  3. data = [1, 2, 1, 1, 0, 0, 3]
  4. success = []
  5. fail = []
  6.  
  7. counter = Counter(data)
  8.  
  9. for i in data:
  10. if not counter[i]:
  11. continue
  12. counter[i] -= 1
  13. if counter[2 - i]:
  14. counter[2 - i] -= 1
  15. success.append((i, 2 - i))
  16. else:
  17. fail.append(i)
  18.  
  19. print(success, fail)
  20.  
Success #stdin #stdout 0.03s 10200KB
stdin
Standard input is empty
stdout
[(1, 1), (2, 0)] [1, 0, 3]