I have these strings:
>>> a="foo"
>>> b="foo_KEY"
And a dictionary like:
>>> DICT
{
'KEY': ['...'],
'KEY2': ['...', '...'],
...
}
I'd like to build a function that check if the test value is in any key of the input dict:
>>> has_key(a, DICT)
False
>>> has_key(b, DICT)
True
What is the most elegant way to do this task in Python 3?
has_key = lambda a, d: any(k in a for k in d)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With