Use the key
argument for sorted()
. It lets you specify a function that, given the actual item being sorted, returns a value that should be sorted by. If this value is a tuple, then it sorts like tuples sort – by the first value, and then by the second value.
sorted(your_list, key=lambda x: (your_dict[x]['downloads'], your_dict[x]['date']))