I've been searching for the answer to this for a while, but no joy.
I have a dict containing hotel names and prices.
mydict = {'HotelA': 100, 'HotelB': 300, 'HotelC': 200}
I would simply like to iterate over the dict and return a separate dict whose values rank the keys based on lowest to highest values, eg:
mynewdict = {'HotelA': 1, 'HotelB': 3, 'HotelC': 2}
I am aware of how to use sorted
to iterate over a dictionary and provide an ordered list, but am unsure as to the best way to handle the above. All help greatly appreciated.