I have a dictionary with tuples as keys (containing a string and an int) and floats as values. An example:
first = {}
first['monkey', 1] = 130.0
first['dog', 2] = 123.0-
first['cat', 3] = 130.0
first['cat', 4] = 130.0
first['mouse', 6] = 100.0
Now, I need to make a new dictionary, which has the original dictionary key's second element as it's key. The new dictionary's value should be the the place it stands if the keys were sorted. Added to this, there are two exceptions:
- If two dicts have values that are equal, but have different strings in the key, the one with the lowest int in the key should be placed higher.
- If two dicts have values that are equal, but have different ints in the key, they should be placed equal in the new dict and all get the same values.
So, the new dictionary should be as the following:
second[1] = 3
second[2] = 2
second[3] = 4
second[4] = 4
second[6] = 1
I know that it's ignorant to ask someone else to solve my problem without giving my code for it. But i'm simply don't know how to approach the problem. I would be glad if you could provide me with an explanation how would you solve this problem , or even give me a pseudocode of the algorithm.