Skip to content

Instantly share code, notes, and snippets.

@accessnash
Created October 19, 2015 07:27
Show Gist options
  • Save accessnash/f298874e4b8cfc7273e7 to your computer and use it in GitHub Desktop.
Save accessnash/f298874e4b8cfc7273e7 to your computer and use it in GitHub Desktop.
"""Counts the frequency for different numbered words in the text file"""
import sys
def read_text():
inputF = open(sys.argv[1], 'r')
return inputF
openF = read_text()
text = openF.read()
for punc in "&,?-;:.'":
text = text.replace(punc, "")
words = text.lower().split()
lngth_of_words = []
for word in words:
lngth_of_words.append(len(word))
max_l = max(lngth_of_words)
freqs = [0 for i in range(max_l + 1)]
for length in lngth_of_words:
freqs[length] += 1
print("Length Count")
for i, count in enumerate(freqs):
if i != 0:
print("{:>4} {:>8}".format(i, count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment