How to test if a key in a dictionary exists?
supervau at gmail.com
Sat Mar 10 22:17:11 CET 2007
does anyone know how one can test if, e.g., a dictionary 'name' has a
key called 'name_key'?
This would be possible:
keys_of_names = names.keys()
L = len(keys_of_names)
for i in range(L):
if keys_of_names[i] == name_key:
But certainly not efficient. I would expect there is something like:
I appreciate your help!
More information about the Python-list