def sort_dict(input_dict, recurse=False):
    """Return a dict with the same content as input_dict, but sorted.

    If recurse is true, then if the dict value is a dict, we also sort this
    dict, recusively."""
    res = {}
    for key, value in sorted(input_dict.items(), key=lambda i: i[0]):
        if recurse is True and isinstance(value, dict):
            value = sort_dict(value, True)
        res[key] = value
    return res