compile regex pattern only once
This commit is contained in:
parent
7c669afb2c
commit
c9141da37a
1 changed files with 2 additions and 1 deletions
|
|
@ -12,8 +12,9 @@ def get_lines(filename: str) -> list:
|
|||
|
||||
def part1_get_result_sum(lines: list) -> int:
|
||||
result_sum = 0
|
||||
pattern = re.compile(r"mul\((\d+),(\d+)\)")
|
||||
for line in lines:
|
||||
matches = re.findall(r"mul\((\d+),(\d+)\)", line)
|
||||
matches = re.findall(pattern, line)
|
||||
for match in matches:
|
||||
result_sum += int(match[0]) * int(match[1])
|
||||
return result_sum
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue