Python: How to check if keys exists and retrieve value from Dictionary in descending priority

前端 未结 4 2069
忘掉有多难
忘掉有多难 2021-01-03 19:07

I have a dictionary and I would like to get some values from it based on some keys. For example, I have a dictionary for users with their first name, last name, username, ad

4条回答
  •  暖寄归人
    2021-01-03 19:40

    Use .get(), which if the key is not found, returns None.

    for i in keySet:
        temp = myDict.get(i)
        if temp is not None:
            print temp
            break
    

提交回复
热议问题