django models - Pythonic dictionary traversal -


I often find myself in situations where I need to cross and parse a semi-complex JSON structure . During the translators, some dictionaries are expected for the key , and their value is appropriate in an object ( foo. Mapping is required. .

Any remaining key / value that will need to be individually mapped to an object ( foo.additional_attributes (** remaining) ) and it Variable keys can be controlled as / value attributes.

Is there a combination of build-in functions to simplify such traversal, mapping and isolation, making it more dynamic and Pythonic?

You can use the pop method of the dictionary: > for the key in the required_keys: foo __dict __ [key] = d.pop (key) foo.additional_attributes (** d)

Comments