Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created May 19, 2013 20:35
Show Gist options
  • Save khajavi/5608878 to your computer and use it in GitHub Desktop.
Save khajavi/5608878 to your computer and use it in GitHub Desktop.
example of dictionary data type
import string
import sys
words = {}
strip = string.whitespace + string.punctuation + string.digits + "\"'"
for filename in sys.argv[1:]:
for line in open( filename ):
for word in line.lower().split():
word = word.strip( strip )
if len( word ) > 2:
words[word] = words.get( word, 0 ) + 1
for word in sorted( words ):
print( "'{0}' occurs {1} times".format( word, words[ word ] ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment