06
Jul
Learn how to check if the key of an dictionary exists using Python
Let’s say you have an associative array like: {“key1”: 22, “key2”: 42}
Then if you need to check key1 exists using python, following code will do that.
if key in array: # do something
Note: Be sure to put the key name in quotes if it’s a string.
Associative arrays are called dictionaries in Python and you can learn more about them in the stdtypes documentation