Skip to content
Advertisement

How to delete values in a dict based on the presence of child values

I have a dict that looks like this:

JavaScript

How can I iterate over the elements of this dict, and exclude any element that has “‘parent’ : None” and no child element (meaning, no other element in this dict has this one as a parent).

Expected output:

JavaScript

Advertisement

Answer

I think this function can help you

JavaScript

To use it:

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