A nested dictionary is a dictionary whose keys are strings and whose values are string or other nested dictionaries. Given a string representation , we need to return a String representation where the entries are sorted by key(within each nested dictionary)
Input: { b:{cb:cranberry,bb:blueberry},a:apple,c:cherry}
Output: { a:apple,b:{bb:blueberry,cb:cranberry},c:cherry}
Here entries in outermost dictionary have been reordered by key (i.e from b,a,c
to a,b,c
) . Similarly , the entries in innermost dictionary have been reordered by key(i.e from cb,bb
to bb,cb
)
Also, Note : Output will have same general format as input string. except that within each nested dictionary, keys should be sorted in increasing lexicographic order ( eg. a<b<bb<bbb<bc<c
)