I want to rename the dictionary keys, which are ints, and I need them to be ints with leading zeros so that they sort correctly.
for example, my keys are like:
'1','101','11'
and I need them to be:
'001','101','011'
this is what i am doing now but i know there is a better way
tmpDict = {}
for oldKey in aDict:
tmpDict['%04d'%int(oldKey)] = aDict[oldKey]
newDict = tmpDict
source
share