Skip to content

Instantly share code, notes, and snippets.

@Suor
Created June 2, 2013 05:02
Show Gist options
  • Save Suor/5692674 to your computer and use it in GitHub Desktop.
Save Suor/5692674 to your computer and use it in GitHub Desktop.
apply_schema.py
from funcy import join
def apply_el(data, el):
if isinstance(el, str):
return {el: data.get(el)}
elif isinstance(el, dict):
return {
k: apply_schema(data.get(k), v)
for k, v in el.items()
}
elif isinstance(el, list):
return [apply_schema(item, el) for item in data]
else:
raise ValueError("Don't know how to apply schema element %s" % el)
def apply_schema(data, schema):
return join(apply_el(data, el) for el in schema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment