I have a dictionary that I am using. I occasionally delete values from it and then have to go back through and rename the keys. I am accomplishing the renaming like so:
TestDic = {0: "Apple", 2: "Orange", 3: "Grape"}
print(TestDic)
TempDic = {}
i = 0
for Key, DictValue in TestDic.iteritems():
TempDic[i] = DictValue
i += 1
TestDic= TempDic
print(TestDic)
Outputs:
{0: 'Apple', 1: 'Orange', 2: 'Grape'}
Great. Now is there a better way? I saw this, but I cannot pop off the old key, as the old key/value pair are gone. And this deals with reformatting the int/floats in the dictionary.