I am looking for an easy way to be able to get a value from a dictionary, and if its not there, return the key that the user passed in.
E.g.:
>>> 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'
These will always be strings, but basically I am creating a language map and need an easy way to get a value, if it exists return it else return the key.
Is there any easy way to do this? Or should I just extend dict and do it manually.
Should be possible with a lambda function
Edit: Sorry I misread the question. As the comment above already said. The way to go is extending the dict class.