Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index error when string contains digits #3

Open
haydenc opened this issue Apr 13, 2016 · 3 comments
Open

Index error when string contains digits #3

haydenc opened this issue Apr 13, 2016 · 3 comments
Assignees

Comments

@haydenc
Copy link

haydenc commented Apr 13, 2016

I think the most useful scenario for this library would be the one I'm trying to use it for - parsing user inputted data, so it should handle situations where the user has entered digits.

e.g. word_to_num("twenty million") == word_to_num("20 million")

@haydenc
Copy link
Author

haydenc commented Apr 13, 2016

Had a look at doing this myself - looks like the main challenge is adapting your definition of words to split things like 22million.
At the moment I've got
def parse_alpha_numeric_word(char_block):
word_groups = re.split(r"(\d_)([a-z]_)", char_block)
return [word for word in word_groups if word != '']
Which does the job, but I can't figure out how to not match the empty strings either side (regex not my strong suit).

Then we have

split_words = number_sentence.split()
split_words = [word for char_block in split_words for word in parse_alpha_numeric_word(char_block)]

To get it back into a flat list of words

@akshaynagpal
Copy link
Owner

Thanks for pointing this issue @haydenc . Will look into this in the next version release. Also, you are most welcome to contribute and resolve this issue.

@akshaynagpal
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants