Check if a key already exists in a dictionary

PHOTO EMBED

Saved by @bravocoder #python

if 'key1' in dict:
  print "blah"
else:
  print "boo"
content_copyCOPY

Will be much faster as it uses the dictionary's hashing as opposed to doing a linear search, which calling keys would do.

https://stackoverflow.com/questions/1602934/check-if-a-given-key-already-exists-in-a-dictionary