strip ands, correct test
This commit is contained in:
parent
18c3996020
commit
734f0dd20e
2 changed files with 4 additions and 1 deletions
|
|
@ -717,7 +717,7 @@ class TestIntConversions(TestCase):
|
||||||
self.assertEqual(20, utils.str2int("twenty"))
|
self.assertEqual(20, utils.str2int("twenty"))
|
||||||
|
|
||||||
# multi-place numbers
|
# multi-place numbers
|
||||||
self.assertEqual(2345, utils.str2int("two thousand, three hundred and thirty-five"))
|
self.assertEqual(2345, utils.str2int("two thousand, three hundred and forty-five"))
|
||||||
|
|
||||||
# ordinal numbers
|
# ordinal numbers
|
||||||
self.assertEqual(1, utils.str2int("1st"))
|
self.assertEqual(1, utils.str2int("1st"))
|
||||||
|
|
|
||||||
|
|
@ -2811,6 +2811,9 @@ def str2int(number):
|
||||||
# it's a single number, return it
|
# it's a single number, return it
|
||||||
return i
|
return i
|
||||||
|
|
||||||
|
# remove optional "and"s
|
||||||
|
number = number.replace(" and "," ")
|
||||||
|
|
||||||
# split number words by spaces, hyphens and commas, to accommodate multiple styles
|
# split number words by spaces, hyphens and commas, to accommodate multiple styles
|
||||||
numbers = [ word.lower() for word in re.split(r'[-\s\,]',number) if word ]
|
numbers = [ word.lower() for word in re.split(r'[-\s\,]',number) if word ]
|
||||||
sums = []
|
sums = []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue