GoDaddy Domains needs to filter a list of domain names for search and machine learning workflows. Given domain names and wildcard patterns, return every domain matching at least one pattern while preserving the original order.
A pattern supports:
*, which matches zero or more characters?, which matches exactly one character., which match themselvesMatching must cover the entire normalized domain. Normalize both domains and patterns by converting them to lowercase and removing one trailing period, if present. Do not remove or otherwise alter internal periods. Return each matching input domain at most once, even if multiple patterns match it.
Implement filter_domains(domains, patterns), where domains and patterns are lists of strings. Return a list of the original domain strings that match at least one normalized pattern, in their original order.
def filter_domains(domains, patterns):