16 lines
422 B
Python
16 lines
422 B
Python
from collections import OrderedDict
|
|
|
|
|
|
def sort_recursive(dictionary):
|
|
"""Recursively sorts nested dictionaries."""
|
|
sorted_list = OrderedDict(sorted(dictionary.items(), key=lambda x: x[0]))
|
|
for key, value in sorted_list.items():
|
|
if isinstance(value, dict):
|
|
sorted_list[key] = sort_recursive(value)
|
|
return sorted_list
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import doctest
|
|
doctest.testmod()
|