else/Toolbox/unique.py

23 lines
410 B
Python
Raw Normal View History

2016-12-05 01:50:52 +00:00
'''
Keep the unique lines coming from stdin and print them.
'''
from voussoirkit import clipext
import sys
if len(sys.argv) > 1:
text = clipext.resolve(sys.argv[1])
else:
text = clipext.resolve('!input')
text = text.split('\n')
new_text = []
seen = set()
for item in text:
if item not in seen:
new_text.append(item)
seen.add(item)
new_text = '\n'.join(new_text)
print(new_text)