You can filter information from any iteration (including a string) using the filter function or understanding. For example, any of them:
digits = filter(str.isdigit, input_string) digits = (character for character in input_string if character.isdigit())
... will give you an iterable figure. If you want to convert each of the numbers to numbers, then any of them will do this:
numbers = map(int, filter(str.isdigit, input_string)) numbers = (int(character) for character in input_string if character.isdigit())
So, to get the sum of all the numbers, skipping the letters, just pass one of them to the sum function:
total = sum(map(int, filter(str.isdigit, input_string))) total = sum(int(character) for character in input_string if character.isdigit())
From your last paragraph:
I cannot check if the element is a digit with isDigit, because the elements must apparently be integers, and I cannot convert the elements into a list to integers
At first it is isdigit , not isdigit . Secondly, isdigit is a method for strings, not integers, so you are mistaken in thinking that you cannot call it in strings. In fact, you have to call it in strings before converting them to integers.
But this brings up another option. In Python, it's often easier to ask forgiveness than permission . Instead of figuring out if we can convert each letter to int, and then do it, we can just try to convert it to int and then handle a possible glitch. For instance:
def get_numbers(input_string): for character in input_string: try: yield int(character) except TypeError: pass
Now just:
total = sum(get_numbers(input_string))