2 ms·
As they call out in the article, accurately counting words is a bit more complicated that splitting by space. You need to account for all sorts of punctuation
by Twirrim 4y ago
As they call out in the article, accurately counting words is a bit more complicated that splitting by space. You need to account for all sorts of punctuation etc.
When I've been asked this in programming interviews, I've almost always been expected to produce something like the code in the article (and do), but usually I'd point to something like the NLTK library as a better approach. It's polished and highly capable, and handles probably just about every edge case there is.