Skip to content
Advertisement

Python: how parse this dict recursively?

I’ve a flat dict with entities. Each entity can have a parent. I’d like to recursively build each entity, considering the parent values.

Logic:

  1. Each entity inherits defaults from its parent (e.g. is_mammal)
  2. Each entity can overwrite the defaults of its parent (e.g. age)
  3. Each entity can add new attributes (e.g. hobby)

I’m struggling to get it done. Help is appreciated, thanks!

JavaScript

Expected output:

JavaScript

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement