Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0005还有问题,pillow不是很熟悉 #251

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
0006 was lost
  • Loading branch information
ZTCooper committed Oct 9, 2017
commit fd30a42f7fbf8a131cc5bdea7eae7073dcb47ebc
26 changes: 26 additions & 0 deletions ztcooper/0006/0006.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from nltk.tokenize import word_tokenize
from nltk.probability import FreqDist
from nltk.corpus import stopwords

files = os.listdir(os.curdir)
for file in files:

if os.path.splitext(file)[1] == '.txt':
with open(file) as f:
text = f.read()

tokens = word_tokenize(text.lower())
sw = stopwords.words('english')
puncs = [',', '.', ';', ':', '"',"''"]
clean = [token for token in tokens if (token not in sw) and (token not in puncs)]

freq = FreqDist(clean)
m = max([v for v in freq.values()])

for k,v in freq.items():
if v == m:
target = k

with open('result.txt','a') as w:
w.write(os.path.splitext(file)[0]+" : "+target+'\n')