with open("input") as f: lines = [n.strip() for n in f.readlines()] solution = 0 for line in lines: literal_count = len(line) char_count = 2 # surrounding double quotes: '"' i = 0 while i < len(line): char = line[i] if char in ['"', "\\", ""]: char_count += 1 char_count += 1 i += 1 print(f"{line}: {literal_count=}, {char_count=}") solution += char_count - literal_count print(solution)