For example, let's look at this Python code that flattens a nested dictionary: def flatten_dict ( d , parent_key = '' , sep = '.' ) : items = [ ] for k , v in d . items ( ) : new_key = f" { parent_key } { sep } { k } " if parent_key else k if isinstance ( v , dict ) : items . extend ( flatten_dict ( v , new_key , sep ) . items ( ) ) else : items . append ( ( new_key , v ) ) return dict ( items ) nested_dictionary = { 'key' : 3 , 'foo' : { 'a' : 5 , 'bar' : { 'baz' : 8 } } } print ( flatten_dict ( nested_dictionary ) ) This code iterates through the dictionary's items. If a value is another dictionary, it recursively calls the flatten_dict() function with the current key combined as the parent key. If the value is not a dictionary, it simply appends the key-value pair to the items list. Ultimately, the items list is transformed into a dictionary and returned. This process flattens the nested_dictionary , resulting in: {'key': 3, 'foo.a': 5, 'foo.bar.baz': 8} .