So I have a dictionary:
{\'a\': {\'b\': {\'c\': \'d\', \'e\': \'f\'}}}
I need to create a dictionary as follows:
{\'c\':\'d\',
Note that you do not necessarily need to use yield:
yield
def last(d): c = [i for b in d.items() for i in ([b] if not isinstance(b[-1], dict) else last(b[-1]))] return c print(dict(last({'a': {'b': {'c': 'd', 'e': 'f'}}})))
Output:
{'c': 'd', 'e': 'f'}