Deduplicate solutions
(solutions: List[str])
| 106 | |
| 107 | |
| 108 | def deduplicate(solutions: List[str]) -> List[str]: |
| 109 | """Deduplicate solutions""" |
| 110 | asts = set() |
| 111 | deduplicated = [] |
| 112 | for solution in solutions: |
| 113 | solution = re.sub(r"#[^\n]*", "", solution) |
| 114 | solution = re.sub(r'"""[^"]*"""', "", solution) |
| 115 | solution = re.sub(r"'''[^']*'''", "", solution) |
| 116 | try: |
| 117 | ast_string = ast.dump(ast.parse(solution)) |
| 118 | except SyntaxError: |
| 119 | continue |
| 120 | except MemoryError: |
| 121 | continue |
| 122 | if ast_string not in asts: |
| 123 | asts.add(ast_string) |
| 124 | deduplicated.append(solution) |
| 125 | return list(deduplicated) |
| 126 | |
| 127 | |
| 128 | def test_solutions( |