Created
October 19, 2015 07:27
-
-
Save accessnash/f298874e4b8cfc7273e7 to your computer and use it in GitHub Desktop.
This file contains 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
"""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