Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # encoding: utf-8
- from sys import argv, exit
- # Source file parsing
- def parse_list(filename):
- result = []
- with open(filename, 'r', encoding="UTF-8") as reader:
- for line in reader:
- clean_line = line.strip().lower()
- if clean_line:
- result.append(clean_line)
- return frozenset(result)
- def write_list(lines, filename):
- with open(filename, 'w', encoding="UTF-8") as out_file:
- for line in sorted(lines):
- print(line, file=out_file)
- if __name__ == "__main__":
- # Parsing arguments
- try:
- source_file = argv[1]
- except IndexError:
- print("You must supply the input file!")
- exit(1)
- try:
- destination_file = argv[2]
- except IndexError:
- destination_file = source_file
- lines = parse_list(source_file)
- write_list(lines, destination_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement