Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # inverse
- from collections import Counter
- from itertools import repeat
- def remove_opposite_pairs(seq):
- dplus = Counter(seq)
- dminus = Counter(-x for x in seq)
- for x,n in (dplus - dminus).items():
- yield from repeat(x, n)
- lsts = [[326, -326, 336, -336, 336],
- [-35, 35, 838, -838, 440],
- [544, -544, 544],
- [-25, 25, 32, -32, -32, 56, 79],
- [-1, 0, 1, -1, -1]]
- for l in lsts:
- print(list(remove_opposite_pairs(l)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement