Say I have the following dictionary,
d = {'foo': 1,
'bar': 2,
'baz:foo', 3,
'baz:bar', 4
}
and I want to find whether any 'baz' keys exist in the dict. I have the following, which works fine.
for key in d:
if key.startswith('baz'):
do_something()
break
I would prefer something like the following:
if 'baz*' in d:
do_something()
but I haven't been able to make it work.
Is there a better way to search for partial keys in a python dictionary?