Skip to content

Instantly share code, notes, and snippets.

View matyasfodor's full-sized avatar
🦕

Mátyás Fodor matyasfodor

🦕
  • BenevolentAI
  • London
View GitHub Profile
bazById = {baz.id: baz for baz in foo.bazs}
foo.bar.bazs = {bazById[k]:v for k, v in foo.bar.bazs.items()}
def myfunc(foo):
...
barById = {b.id: b for b in foo.bar.bazs.keys()}
...
@matyasfodor
matyasfodor / parse_json_object.py
Last active July 16, 2017 19:47
This is how to parse JSON as object (recursively)
import json
from collections import namedtuple
x = json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))