Use anyor all, depending on whether you want to check if any of the characters are in the dictionary, or all of them. Here is a sample code that suggests what you want all:
>>> s='abcd'
>>> d={'a':1, 'b':2, 'c':3}
>>> all(c in d for c in s)
False
Alternatively, you can get the character set in your string, which are also keys in your dictionary:
>>> set(s) & d.keys()
{'a', 'c', 'b'}
source
share