def deep_sort_lists(value):
if isinstance(value, dict):<EOL><INDENT>return {k: deep_sort_lists(v) for k, v in value.items()}<EOL><DEDENT>if isinstance(value, list):<EOL><INDENT>if sys.version_info.major < <NUM_LIT:3>:<EOL><INDENT>return sorted((deep_sort_lists(x) for x in value))<EOL><DEDENT>else:<EOL><INDENT>return sorted((deep_sort_lists(x) for x in value), key=cmp_to_key(custom_list_data_comparator))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return value<EOL><DEDENT>
Custom sorting implemented as a wrapper on top of Python's built-in ``sorted`` method. This is necessary because
the previous behavior assumed lists were unordered. As part of migration to Py3, we are trying to
retain the same behavior. But in Py3, lists with complex data types like dict cannot be sorted. Hence
we provide a custom sort function that tries best sort the lists in a stable order. The actual order
does not matter as long as it is stable between runs.

This implementation assumes that the input was parsed from a JSON data. So it can have one of the
following types: a primitive type, list or other dictionaries.
We traverse the dictionary like how we would traverse a tree. If a value is a list, we recursively sort the members
of the list, and then sort the list itself.

This assumption that lists are unordered is a problem at the first place. As part of dropping support for Python2,
we should remove this assumption. We have to update SAM Translator to output lists in a predictable ordering so we
can assume lists are ordered and compare them.