- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmostCommonWordsFile.py
More file actions
Latest commit
23 lines (18 loc) · 750 Bytes
/
Copy pathmostCommonWordsFile.py
File metadata and controls
23 lines (18 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-
importre
importcollections
NO_OF_MOST_COMMONS=10
EXCLUDE_STOPWORDS='n'
defmostCommonWords(EXCLUDE_STOPWORDS='y'):
words= []
withopen('WarAndPeace.txt', 'r') asf:
text=f.read().lower()
words=re.findall(r'[a-záéëíÀóúèîôàçâêïýöäüÁœÉæ]+', text)
ifEXCLUDE_STOPWORDS.lower() =='n':
withopen('stopwords.txt', 'r') asf:
stopwords=f.read().split()
words= [
wordforwordinwordsifwordnotinstopwordsandlen(word) >3]
wordCount=collections.Counter(words)
return''.join('{} : {}\n'.format(word, count) forword, countinwordCount.most_common(NO_OF_MOST_COMMONS))
print(mostCommonWords(EXCLUDE_STOPWORDS))