-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader_parser.py
More file actions
34 lines (29 loc) · 1.41 KB
/
reader_parser.py
File metadata and controls
34 lines (29 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def process_text_file(input_file):
# Dictionary to store unique strings
unique_strings = {}
try:
# Read the input file
with open(input_file, 'r', encoding='utf-8') as file:
for line in file:
# Check if line contains ": "
if ": " in line:
# Split the line at ": " and take the second part
parts = line.split(": ", 1)
if len(parts) > 1:
# Get the string after ": " and strip whitespace
string_after = parts[1].strip()
# Add to dictionary if not empty and starts with a letter
if string_after and string_after[0].isalpha():
unique_strings[string_after] = True
# Write unique strings to output.txt
with open('output.txt', 'w', encoding='utf-8') as output_file:
for string in unique_strings.keys():
output_file.write(f"{string}\n")
print(f"Processing complete. Found {len(unique_strings)} unique strings.")
except FileNotFoundError:
print(f"Error: Input file '{input_file}' not found.")
except Exception as e:
print(f"An error occurred: {str(e)}")
if __name__ == "__main__":
input_file = "input.txt" # Change this to your input file name
process_text_file(input_file)