Skip to content

Instantly share code, notes, and snippets.

@carlosble
Created July 7, 2020 15:48
Show Gist options
  • Save carlosble/078a3e8c2691e3da495bb6d94f0d2334 to your computer and use it in GitHub Desktop.
Save carlosble/078a3e8c2691e3da495bb6d94f0d2334 to your computer and use it in GitHub Desktop.
String calculator Kata 2
import re
def sum_numbers_in(expression: str) -> int:
if expression is None or expression == "":
return 0
if "," in expression:
tokens = expression.split(',')
total = 0
for token in tokens:
total = total + parse_int(token)
return total
return parse_int(expression)
def parse_int(token):
if re.match("^[0-9]+$", token):
return int(token)
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment