def filter_pattern(values, pattern): for value in values: if not pattern or fullmatch(pattern, value): yield value