def match_pattern(input_line, pattern):
if len(pattern) == 1:
return pattern in input_line
elif pattern == "\d":
return any(char.isdigit() for char in input_line)
elif pattern == "\w":
return any(char.isalnum() or char == '_' for char in input_line)
elif pattern[0] == '[' and pattern[-1] == ']':
return any(True for char in input_line if char in pattern[1:-1])
elif pattern.startswith("[^") and pattern.endswith("]"):
return not any(char in pattern[2:-1] for char in input_line)
else:
raise RuntimeError(f"Unhandled pattern: {pattern}")
I dont see anything wrong with this line of code in terms of returning a negative character group.
elif pattern[0:2] == "[^" and pattern[-1] == "]":
return not any(char in pattern[2:-1] for char in input_line)
Inside the any function I have a list comprehension which I think make sense and the only thing I can think is wrong is the condition but I am truly stuck on this problem.
Any help would be appreciated. Thanks