Last active
December 27, 2015 16:59
-
-
Save joshuaboy7/7359030 to your computer and use it in GitHub Desktop.
This script imports a text returns unique words and their counts.
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 globe | |
import csv | |
""" | |
flist=glob.glob(r'C:\\Python27\\*.txt') | |
fil = open('C:\\Python27\\README.txt') | |
new_file = open('C:\Python27\\freq_list.txt', 'w') | |
""" | |
fil = open("/Users/StefanCelMare/Desktop/PythonReadme.txt") | |
#fil = 'asfdaskfj1231234!@#$!@#$!adfasdf' | |
new_file = open('/Users/StefanCelMare/Desktop/freq_list.csv', 'w') | |
fil = open("/Users/StefanCelMare/Desktop/PythonReadme.txt") | |
text = fil.read() | |
fil.close() | |
textClean = '' | |
for i in text: | |
if i.isalpha() or i.isspace(): | |
textClean+=i | |
textLow = string.lower(textClean) | |
textVar = textLow.split() | |
newText = '' | |
for w in textVar: | |
if w not in newText.split(): | |
w+=' ' | |
newText+=w | |
textSplit = newText.split() | |
freq_list = '' | |
for w in newText.split(): | |
wordCount = textVar.count(w) | |
if wordCount > 1: | |
print w, wordCount | |
freq_list = freq_list + w + ',' + str(wordCount) + '\n' | |
new_file.write(freq_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment