问题描述
该笔记将记录:常用的 Python Dictionary 操作
解决方案
d = {'1': 'one', '3': 'three', '2': 'two', '5': 'five', '4': 'four'} # 判断是否包含某个 Value 'one' in d.values() # 从字典中取值, dictionary["Name"] dictionary.get("Name") # 推荐,该方法能够设置默认值,不会 rasie KeyError
参考文献
How to check if a value exists in a dictionary (python)
python – Why dict.get(key) instead of dict[key]? – Stack Overflow
How to fix Python KeyError Exceptions in simple steps?