Created
May 19, 2013 20:35
-
-
Save khajavi/5608878 to your computer and use it in GitHub Desktop.
example of dictionary data type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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