Skip to content

Instantly share code, notes, and snippets.

@telendt
Created March 22, 2017 13:56
Show Gist options
  • Save telendt/5bd553a97dac3d7309e9381fd8099997 to your computer and use it in GitHub Desktop.
Save telendt/5bd553a97dac3d7309e9381fd8099997 to your computer and use it in GitHub Desktop.
Sliding window uniq...
#!/usr/bin/env python
import collections
import sys
MAX_SIZE = 50
if __name__ == '__main__':
d = collections.OrderedDict()
for line in sys.stdin:
if line not in d:
print(line, end='', flush=True)
if len(d) >= MAX_SIZE:
d.popitem()
d[line] = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment