I have a dictionary that looks like this:
example_dict = {
0: [(1,2),(3,4),(3,4),(4,5)],
1: [(1,2),(3,4),(5,6),(7,8)],
2: [(4,5),(7,8)]}
I would like to get a sorted representation of this dictionary by number of elements in each list after ‘temporarily’ removing duplicates (only for the purpose of sorting, I don’t want to delete remove tuples). So sorted example_dict would have the following (ascending) order of keys: 2,0,1.
Is there any efficient, Pythonic way to do this?
Output:
Or if you want the dictionary items sorted as a list of tuples:
Output: