Python check if a given key exists in a dictionary
Posted by Samath
Last Updated: January 13, 2017

This program basically check if a given key exists in a dictionary. This is written using the python programming language. 

d = {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}


print 'd contains k1? ', d.has_key('k1')

print 'd contains k4? ', d.has_key('k4')

print 'k2 in d? ', 'k2' in d