I am trying to map values between dictionary and list in Python. I am trying to count the number of objects I found in the image: For example I found: Squares:3 Rectangles:4 Oval=2 Triangle=1
Now I append all of them to a list in descending order.
The list becomes:[4,3,2,1]
Now I somehow wanna say that '4' in the list corresponds to 'rectangle', '2' corresponds to 'Oval' I am trying to use a dictionary but struggling.
Since , I am doing this for multiple images, the output will be different. For example, the next image gives the results:
Squares:4 Rectangles:3 Oval=1 Triangle=2
Now the List becomes [4,3,1,2]
Therefore, it should map '4' to Squares and not rectangle
mydict = {4: 'Rectangles'}, thenmydict[4]will give you'Rectangles'. But why use both when you just need a dictionary? You seem to have unnecessary objects.Counterand itsmost_commonmethod. docs.python.org/2/library/…