Advertisement
imcrazytwkr

uSort

Dec 11th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # encoding: utf-8
  3.  
  4. from sys import argv, exit
  5.  
  6. # Source file parsing
  7. def parse_list(filename):
  8.     result = []
  9.  
  10.     with open(filename, 'r', encoding="UTF-8") as reader:
  11.         for line in reader:
  12.             clean_line = line.strip().lower()
  13.             if clean_line:
  14.                 result.append(clean_line)
  15.  
  16.     return frozenset(result)
  17.  
  18. def write_list(lines, filename):
  19.     with open(filename, 'w', encoding="UTF-8") as out_file:
  20.         for line in sorted(lines):
  21.             print(line, file=out_file)
  22.  
  23. if __name__ == "__main__":
  24.     # Parsing arguments
  25.     try:
  26.        source_file = argv[1]
  27.     except IndexError:
  28.        print("You must supply the input file!")
  29.        exit(1)
  30.  
  31.     try:
  32.         destination_file = argv[2]
  33.     except IndexError:
  34.         destination_file = source_file
  35.  
  36.     lines = parse_list(source_file)
  37.     write_list(lines, destination_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement