'Is it possible to get the sum of a dictionary JSON with values of different data types in python

I am trying to get the sum of the values from a dictionary within a JSON file, but some of the values are a different data type. Only the values that are numbers I want added.

{"id": "id-1", "id name": "city 1", "Level": "software engineer", "days total 1": "100", "days total 2": "111", "days total 3": "56", "days total 4": "158", "days total 5": "48", "days total 6": "37", "days total 7": "188", "days total 8": "121", "date": "04/06/2022 00:00:00 AM"}

Is it possible to still get the sum of the values from this dictionary JSON?

sum(int(dictionary.values())) won't work since some the strings are actually words or dates.

Any help would be appreciated.



Solution 1:[1]

This will give you the sum of values that are digits

sum(int(x) for x in dictionary.values() if x.isdigit())

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 smasd