Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- blocks = []
- current_place = None
- entries = []
- with open("R:\\input.txt", "r", encoding="utf-8") as input_file:
- for line in input_file:
- line = line.strip()
- if not line:
- continue
- if "\t" not in line: # A place heading
- if current_place is not None:
- blocks.append((current_place, entries))
- current_place = line
- entries = []
- else: # A candidate entry
- entries.append(line)
- if current_place is not None:
- blocks.append((current_place, entries))
- count = 0
- with open("R:\\output.txt", "w", encoding="utf-8") as output_file:
- for place, entries in blocks:
- if len(entries) == 1:
- count += 1
- output_file.write(f"{count}. {place}\n")
Advertisement
Add Comment
Please, Sign In to add comment