mardi 30 juin 2015

Reading numeric keys from JSON file

Let's say I store a dictionary's values in JSON file. Here is the simplified code:

test = {}
for i in range(10):
    for j in range(15):
        test['{},{}'.format(i, j)] = i * j

with open('file1.json', 'w') as f:
    json.dump(test, f)

I have hard time reading back from this file. How can I read back from this file into a dictionary with elements like key as [i,j] and value as i*j?

Aucun commentaire:

Enregistrer un commentaire