Skip to content

Instantly share code, notes, and snippets.

@perryism
Created April 24, 2020 17:21
Show Gist options
  • Save perryism/0ca903bd61116a6ee83e41a29ad7f339 to your computer and use it in GitHub Desktop.
Save perryism/0ca903bd61116a6ee83e41a29ad7f339 to your computer and use it in GitHub Desktop.
Return an intercept(or not) list
import re
list_one = ["apple", "orange", "banana", "pineapple", "watermelon"]
list_two = ["apple", "water"]
filter_func = lambda x, lst: all(i not in x for i in lst)
select_func = lambda x, lst: any(i in x for i in lst)
def intercept(list_one, list_two, select=True):
func = select_func if select else filter_func
return filter(lambda x: func(x, list_two), list_one)
result = intercept(list_one, list_two, False)
assert list(result) == [ "orange", "banana" ]
result = intercept(list_one, list_two, True)
assert list(result) == [ "apple", "pineapple", "watermelon" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment