Created
September 19, 2019 14:56
-
-
Save jsettlem/f045ca4b293f5de7e58df78a0a6a8791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Optional | |
def main(): | |
items = [ | |
"campbells soup", | |
"bonnie and kyled", | |
"the wonderful end of the world", | |
"my name is matthew" | |
] | |
print(apply_filter(items, [ | |
["camp", "kyle"], | |
["matt"], | |
None | |
])) | |
print(apply_filter(items, [None, None, None])) | |
print(apply_filter(items, [["nothing"], ["aat"], ["all"]])) | |
def apply_filter(items: List, filters: List[Optional[List]]) -> List: | |
if all(f is None for f in filters): | |
return items | |
return list(filter(lambda item: any((f is not None and any(needle in item for needle in f) for f in filters)), items)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment