I know this is going to sound like I just need to use json.loads from the title. But I don't think that's the case here. Or at least I should be able to do this without any libraries (plus I want to understand this and not just solve it with a library method).
What I have currently is a dictionary where the keys are words and the values are total counts for those words:
myDict = { "word1": 12, "word2": 18, "word3": 4, "word4": 45 }
and so on...
what I want is for it to become something like the following (so that I can insert it into a scraperwiki datastore):
myNewDict = {"entry": "word1", "count": 12, "entry": "word2", "count": 18, "entry": "word3", "count": 4, "entry": "word4", "count": 45}
I figured I could just loop over myDict
and insert each key/value after my new chosen keys "entry" and "count" (like so):
for k, v in myDict.iteritems():
myNewDict = { "entry": k, "count": v }
but with this, myNewDict
is only saving the last result (so only giving me myNewDict={"entry":"word4", "total":45}
what am I missing here?