How can I check if the characters in a string are in a dictionary of values?

前端 未结 3 996
日久生厌
日久生厌 2021-01-16 02:14

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?

3条回答
  •  时光取名叫无心
    2021-01-16 02:42

    string = "hello" 
    dictionary = {1:"h", 2:"e", 3:"q"}
    for c in string:
        if c in dictionary.values():
            print(c, "in dictionary.values!")
    

    If you wanted to check if c is in the keys, use dictionary.keys() instead.

提交回复
热议问题