Skip to content

Instantly share code, notes, and snippets.

@malithjkmt
Created August 13, 2017 04:58
Show Gist options
  • Save malithjkmt/e9b89f3081d35231273be6588e4543d2 to your computer and use it in GitHub Desktop.
Save malithjkmt/e9b89f3081d35231273be6588e4543d2 to your computer and use it in GitHub Desktop.
Total & unique word counter
import sys
uniqu_words = {}
total_word_count = 0
inFile = open(sys.argv[1],'r')
for line in inFile:
tokens = line.split()
for word in tokens:
uniqu_words[word] = 1
total_word_count += len(tokens)
print('Total words: ', total_word_count)
print('Unique words: ', len(uniqu_words))
inFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment