import sys file_path = 'core/views.py' with open(file_path, 'r') as f: lines = f.readlines() new_lines = [] seen_keys = set() current_dict = False for line in lines: if '{' in line: current_dict = True seen_keys = set() new_lines.append(line) continue if '}' in line: current_dict = False new_lines.append(line) continue if current_dict: match = re.search(r"'([^']+)':", line) if match: key = match.group(1) if key in seen_keys: if key in ['sign_types', 'has_large_request', 'has_large_sign']: continue # Skip redundant keys seen_keys.add(key) new_lines.append(line) import re # needed in the loop above but imported here for the script with open(file_path, 'w') as f: f.write("".join(new_lines))