Skip to content

Instantly share code, notes, and snippets.

@ryanswanstrom
Created April 4, 2012 14:33
Show Gist options
  • Select an option

  • Save ryanswanstrom/2301823 to your computer and use it in GitHub Desktop.

Select an option

Save ryanswanstrom/2301823 to your computer and use it in GitHub Desktop.
This code will open a file and count the words. Note, this is mostly just psuedo-code. It is not complete and has not been tested.
f=open('/tmp/file.dat')
words = {}
for line in f:
print line
line_words = line.split() // returns an array of words separated by whitespace
for word in line_words:
// get the value
val = words.get(word, false)
if val:
val++;
words[word] = val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment