diff --git a/src/dsa/various.py b/src/dsa/various.py index 4356039..23c9c8d 100644 --- a/src/dsa/various.py +++ b/src/dsa/various.py @@ -62,11 +62,8 @@ def dfs(n: int) -> None: def regex_match(strings: list[str], pattern: str) -> list[str]: - matched = [] - for s in strings: - if re.match(pattern, s): - matched.append(s) - return matched + compiled_pattern = re.compile(pattern) + return [s for s in strings if compiled_pattern.match(s)] def is_palindrome(text: str) -> bool: