0 works

Check if a key already exists in a dictionary


dashboard

Posted by @bravocoder #python

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

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

>> Browse more code snippets

more_vert