Every line of 'python dictionary key exist' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
133 def _check_key_exists(d: dict, key: object, custom_exception=None) -> None: 134 """ Check if a key exists inside a dictionary. Otherwise, raise KeyError or a custom exception. """ 135 try: 136 d[key] 137 except KeyError: 138 if custom_exception: 139 raise custom_exception 140 else: 141 raise KeyError
38 def has_key(key, keys): 39 for k in keys: 40 if k['id'] == key: 41 return True 42 return False