Main Content

Counting Words in Python via the web

Archive - Originally posted on "The Horse's Mouth" - 2009-08-18 17:27:20 - Graham Ellis

I love writing things in Python - it's a great language for achieving a great deal in a short time. And it works well got Simple CGI scripts.

Today's challenge - to count the number of words (and number of DIFFERENT words) in a piece of text, so give an idea of how much work would be involved in translating it.

Web page onto which to paste the text is here. Source code of the script is here. Source code of the Python program is here.

A word of warning - I have taken great care NOT to echo all the text (protects me against injection attacks) - and you need to do the same on your pages. If you're not sure what I mean, read this blog further or I'll tell you more on the Python Course.