python词典值和键

Joh*_*llo 3 python dictionary python-3.x

我有字典叫做人类.我想循环遍历该字典,如果值小于20打印字典键.

humans = {"Danny": 33, "Jenny": 22, "Jackie": 12, "Ashley": 33}
Run Code Online (Sandbox Code Playgroud)

wim*_*wim 5

您好约翰,欢迎来到Stack Overflow.您对问题的描述几乎是一个完美的伪代码,用于实现:

# I've got dictionary called humans. 
humans = {"Danny": 33, "Jenny": 22, "Jackie": 12, "Ashley": 33}

for key, value in humans.items():  # I want to loop through that dictionary 
    if value < 20:                 # and if value is less than 20
        print(key)                 # print dictionary key.
Run Code Online (Sandbox Code Playgroud)