I have a counter objects like
Counter({'the': 10, 'to': 10, 'of': 5, 'independence': 5, 'puigdemont': 5, 'mr': 5, 'a': 4, 'spain': 4, 'for': 4})
I want to reassign each element's value in increasing order by existing value, like
Counter({'the': 0, 'to': 1, 'of': 2, 'independence': 3, 'puigdemont': 4, 'mr': 5, 'a': 6, 'spain': 7, 'for': 8})
Is there any possible method?
Thanks in advance.
Update:
(My English is not very good, so you may skip my explanation and roll down to see the example below.) Sorry, it seems that I didn't make my question clear. Actually the whole Counter object is much longer. The object is obtained from a paragraph, and the value of each word is the occurrence in that paragraph. I want to build a dictionary to replace the words in my paragraph with the corresponding values in the dictionary. The values in the dictionary are ordered by the frequencies of the words in my paragraph, and if two words have the same occurrence, then in alphabetical order.
Example:
string=“where there is smoke there is fire" Occurrences for each word in string: where=1, there=2, is=2, smoke=1, fire=1. So I need a dictionary like:
{“is”: 0, “there”: 1, ”fire”:2 , “smoke”: 3, “where”:4}
The most frequent words are "is" and "there", but in alphabetical order, "i" is in front of "t", so "is" is 0 and "there" is 1.
Is there any good method to accomplish this?
Very thankful!!