You need to be more specific with what you want to do. However, assuming the dictionary you gave:
dict1={"EMP$$1":1, "EMP$$2":2, "EMP$$3":3}
If you want to find out if a particular key was present before trying to request it, you can:
dict1.has_key('EMP$$1') True
Returns True since dict1 has the key EMP$$1 .
You can also forget about key checking and rely on the default value of dict1.get() :
dict1.get('EMP$$5',0) 0
Returns 0 by default dict1 does not have an EMP$$5 key EMP$$5 .
Similarly, you can also use `try / except / structure to search and process missing keys:
try: dict1['EMP$$5'] except KeyError, e: # Code to deal w key error print 'Trapped key error in dict1 looking for %s' % e
Other answers to this question are also great, but we need more information to be more accurate.
dtlussier
source share