Skip to content

Instantly share code, notes, and snippets.

@kangwonlee
Created May 7, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kangwonlee/dd0edd98b1fbdb59b32d89e87b8255dc to your computer and use it in GitHub Desktop.
Save kangwonlee/dd0edd98b1fbdb59b32d89e87b8255dc to your computer and use it in GitHub Desktop.
Unique OR
"""
To augment lines of a text file with an 'OR' logical operator
How to use:
1. Prepare a .txt file with line items to combine with 'OR'
2. Use the file name as argument for the script
3. This script would generate a text
"""
import sys
def main(argv):
txt_list = []
# file descriptor
with open(argv[0], 'rt') as f:
# file line loop
for line in f:
# remove white spaces around the text
if line.strip():
# append if unique
if line.strip() not in txt_list:
txt_list.append(line.strip())
# for better presentation, sort
txt_list.sort()
out_text = ' OR '.join(txt_list)
print(out_text)
if '__main__' == __name__:
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment