Skip to content

utility method clean does not work for nested dicts #383

@martinius74

Description

@martinius74

Discussed in #382

Originally posted by martinius74 February 26, 2024
I was trying to clean my nested dictionaries from any empty string and collections, but somehow, it only considers the root level.
Nested keys are not cleaned.

Looking into the code, the method is using the keys() method.

def clean(d, strings=True, collections=True):
keys = list(d.keys())

If we would use the keypaths() method, it would be able to find all nested keys as well:

def clean(d, strings=True, collections=True):
keys = d.keypaths()

Would it make sense to change this behaviour?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions