I want to check if the characters in any given string are listed in a dictionary of values (as keys) that i have created, how do I do this?
Use any
or all
depending on whether you want to check if any of the characters are in the dictionary, or all of them are. Here's some example code that assumes you want all
:
>>> s='abcd'
>>> d={'a':1, 'b':2, 'c':3}
>>> all(c in d for c in s)
False
Alternatively you might want to get a set of the characters in your string that are also keys in your dictionary:
>>> set(s) & d.keys()
{'a', 'c', 'b'}