Mots clés : pythondictionarypython
91
d = {"key1": 10, "key2": 23} if "key1" in d: print("this will execute") if "nonexistent key" in d: print("this will not")
d = dict() for i in range(100): key = i % 10 d[key] = d.get(key, 0) + 1
from collections import defaultdict d = defaultdict(int) for i in range(100): d[i % 10] += 1
90
if 'key1' in dict: print("blah") else: print("boo")
76
d = {'a': 1, 'b': 2} 'a' in d # <== evaluates to True 'c' in d # <== evaluates to False
68
if 'key1' in my_dict: ...