In [1]:
d = {'a': 'AB', 'b': 'C'}
funcs = {}
for key, value in d.items():
funcs[key] = lambda v: v in value
# True, True, False ?
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'))
# False, True ?
print(funcs['b']('AB'), funcs['b']('C'))
In [2]:
value = "ABCD"
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'), funcs['a']('D'))
In [3]:
d = {'a': 'AB', 'b': 'C'}
def foo(value):
def bar(v):
return v in value
return bar
funcs = {}
for key, value in d.items():
funcs[key] = foo(value)
# True, True, False ?
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'))
# False, True ?
In [4]:
d = {'a': 'AB', 'b': 'C'}
def foo(value):
def bar(v):
return v in value
return bar
funcs = {}
for key, value in d.items():
funcs[key] = foo(value)
# True, True, False ?
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'))
# False, True ?
print(funcs['b']('AB'), funcs['b']('C'))
In [5]:
value = "ABCD"
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'), funcs['a']('D'))
In [6]:
from functools import partial
d = {'a': 'AB', 'b': 'C'}
funcs = {}
for key, value in d.items():
funcs[key] = partial(lambda v, value: v in value, value=value)
# True, True, False ?
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'))
# False, True ?
print(funcs['b']('AB'), funcs['b']('C'))
In [7]:
value = "ABCD"
print(funcs['a']('AB'), funcs['a']('A'), funcs['a']('C'), funcs['a']('D'))