Created
May 7, 2018 16:33
-
-
Save kangwonlee/dd0edd98b1fbdb59b32d89e87b8255dc to your computer and use it in GitHub Desktop.
Unique OR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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