Last active
June 1, 2016 00:17
-
-
Save CodeWithCory/6b51704e8976d32ee6ee3d14153aed8e 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
# Cory Rahman | |
# Python 2.7.8 | |
# To use this program, place the entirety of the text to be counted in | |
# a single .txt file, and target it below under #working files | |
# module | |
import csv | |
from collections import Counter | |
# working files | |
txt_file = "words.txt" | |
csv_file = "WordList1.csv" | |
# | |
stringText=[] | |
with open(txt_file, 'r') as fileVar: | |
inputString=fileVar.read() | |
charactersToKill="1234567890=!@#$%^&*()_+[]\;',./{}|:<>?"+'"' | |
print charactersToKill | |
for ch in inputString: | |
if ch in charactersToKill: | |
pass | |
else: | |
stringText.append(ch) | |
words=''.join(stringText).lower().replace("\n"," ").replace(" "," ").replace(" "," ").replace(" "," ").replace("-"," ") | |
# uses csv module's .reader command to break the txt file up | |
# by the delimiter and storing it in the variable in_txt | |
wordList = words.split(' ') | |
print wordList | |
countDict=Counter(wordList) | |
print countDict | |
writer = csv.writer(open(csv_file, 'wb')) | |
for key, value in countDict.items(): | |
writer.writerow([key, value]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment