def _unique_value_key(x): """Small helper for sorting unique content metadata values""" if isinstance(x, ReadOnlyDict): # turn into an item tuple with keys sorted and values plain # or as a hash if *dicts x = [(k, hash(x[k]) if isinstance(x[k], ReadOnlyDict) else x[k]) for k in sorted(x)] # we need to force str, because sorted in PY3 refuses to compare # any heterogeneous type combinations, such as str/int, tuple(int)/tuple(str) return as_unicode(x)