Skip to content

Instantly share code, notes, and snippets.

@jsettlem
Created September 19, 2019 14:56
Show Gist options
  • Save jsettlem/f045ca4b293f5de7e58df78a0a6a8791 to your computer and use it in GitHub Desktop.
Save jsettlem/f045ca4b293f5de7e58df78a0a6a8791 to your computer and use it in GitHub Desktop.
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