Skip to content

Instantly share code, notes, and snippets.

@etigui
Created October 30, 2019 13:35
Show Gist options
  • Save etigui/abcae14c0b33f8ce523c6e3e1dfbaec2 to your computer and use it in GitHub Desktop.
Save etigui/abcae14c0b33f8ce523c6e3e1dfbaec2 to your computer and use it in GitHub Desktop.
Python: add list to dict and save as json
name = dict()
name["data"] = list()
with open('file.json', 'a') as myfile:
for d in ["1", "2"]:
name["data"].append({"a": d[0], "b": d[1]})
json.dump(name, myfile, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment