def with_prefix(prefixes, words): for prefix in prefixes: lst = [word for word in words if word.startswith(prefix)] yield lst