Skip to content

Instantly share code, notes, and snippets.

@guinslym
Forked from akoskadar/gist:7359046
Last active August 29, 2015 14:06
Show Gist options
  • Save guinslym/f422a7ce95c0d57efd13 to your computer and use it in GitHub Desktop.
Save guinslym/f422a7ce95c0d57efd13 to your computer and use it in GitHub Desktop.
import string
import csv
"""
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')
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