Search for '{{search_term}}'

Exercise: Count words in a file

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

Similar to the exercise in which we counted digits, this time we would like to count words.

Give a file that contains lots of line, each line containig words separated by a space, we would like to count how many times each word appear. For the sake of simplicty in parsing, we can assume that there are no special pnctuations that we might need to get around. Just words separated by a space.

A small input file might look like this:


one word another word
a new sentence and a new word




In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus