Check if a given key already exists in a dictionary
This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. I wanted to test if a key exists in a dictionary before updating the value for the key. I wrote the following code: if ‘key1’ in dict.keys(): print “blah” else: print “boo” … Read more