how can i remove the zero value from python dictionary?

NewDictList = []
res = [{'size': 3, 'class': None, 'styles': None}, {'size': None, 'class': 'my-3 text-light text-center bg-primary', 'styles': None}, {'size': None, 'class': None, 'styles': [{'font-size': '14px'}]}]
for dict_values in res:
    result = {key: value for key, value in dict_values.items() if value is not None}
#result is [{'size': 3}, {'class': 'my-3 text-light text-center bg-primary'}, {'styles': [{'font-size': '14px'}]}]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top