def sort_nested(data):
if isinstance(data, dict):<EOL><INDENT>new_data = {}<EOL>for k, v in data.items():<EOL><INDENT>if isinstance(v, list):<EOL><INDENT>v = sorted(v)<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>v = sort_nested(v)<EOL><DEDENT>new_data[k] = v<EOL><DEDENT>return new_data<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>new_data = []<EOL>for v in sorted(data):<EOL><INDENT>if isinstance(v, list):<EOL><INDENT>v = sort_nested(v)<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>v = sort_nested(v)<EOL><DEDENT>new_data.append(v)<EOL><DEDENT>return new_data<EOL><DEDENT>
Return a new dict with any nested list sorted recursively.