Light Mode
Dark Mode
Do not sum in string "who is 1st here"

Hello,

what can I do better or what should I use? I try to resolve this problem but I have problem with string "who is 1st here" - how to not sum "1st"?

I have two solutions.

First:

def sum_numbers(text: str) -> int:

     return sum(map(int,re.findall('\d+',text)))

Second:

def sum_numbers(text :str) -> int:
        return sum(int(_) for _ in text if _.isdigit())
Created: Aug. 25, 2020, noon
Updated: Aug. 25, 2020, 1:11 p.m.
1
3
User avatar
BElluu