I am looking for an easy way to get the value from the dictionary, and if it is not there, return the key that the user passed.
eg:.
>>> lookup = defaultdict(magic)
>>> print lookup['DNE']
'DNE'
>>> print lookup.get('DNE')
'DNE'
>>> print lookup['exists']
'some other value'
>>> print lookup.get('exists')
'some other value'
They will always be strings, but basically I create a language map and need an easy way to get the value, if it exists, return it, otherwise return the key.
Is there an easy way to do this? Or I just need to expand the dict and do it manually.
source
share