I've recently got an assignment go count the number of WORDS in a sentence. simple enough, right?
you assign the input sentence to a list, you .split() it, and then you .count.
problem is:
a) what if the sentence isn't a sentence? (not ending with a dot)? easy enough to solve: checking is string[-1][-1]=="." and we're done.
b) this is where things get tricky....
what if a word - isn't a word at all??
examples: djgghjdjgf, 7zark7. blizz-ard, twi@ter etc.
I've found pyenchant to solve most issues...but:
- it doesn't recognize words which ends with apostrophe (') like Chris' - as a word. in fact, it doesn't recognize names as words at all....
I can run a double .check: one for pyenchant, but I must do another to see if it's a name..which is a word...
anyone know a similar mudule to pyenchant (which is basically a dictionalry), only with NAMES (if any exists)?
that would be much appreciated.
other solutions are also welcome.
p.s.
the len(s.split()) just can't be right? If I'll right #%#$65477 - that's NOT(!) a word. it's just an item in a list (and I was asked for words, probably real ones).
thanks again.
CodePudding user response:
just as #Patrick Artne said, there's no way to distinguish between names with double meanings and variety of reasons. in a nut shell - what I was asking just can't be done.