In Python what is the most efficient way to do this:
my_var = some_var[\'my_key\'] | None
ie. assign some_var[\'my_key\'] to
some_var[\'my_key\']
You are looking for the get() method of dict.
dict
my_var = some_var.get('some_key')
The get() method will return the value associated with 'some_key', if such a value exists. If the key is not present, then None will be returned.
get()
'some_key'
None