Created
April 24, 2020 17:21
-
-
Save perryism/0ca903bd61116a6ee83e41a29ad7f339 to your computer and use it in GitHub Desktop.
Return an intercept(or not) list
This file contains hidden or 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
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