crunk
5 years ago
8 changed files with 64 additions and 12 deletions
@ -0,0 +1,14 @@ |
|||||
|
def poetry(): |
||||
|
filename = '2013_Wages_for_Facebook_[EN].txt' |
||||
|
path = './manifestos/'+filename |
||||
|
file = open(path, 'r') |
||||
|
manifesto = file.read() |
||||
|
manifesto = manifesto.replace('\n', ' ') |
||||
|
manifesto = manifesto.lower() |
||||
|
words = manifesto.split(' ') |
||||
|
|
||||
|
return result |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
result = poetry() |
||||
|
print('result:', result) |
@ -0,0 +1,28 @@ |
|||||
|
from collections import OrderedDict |
||||
|
from operator import itemgetter |
||||
|
|
||||
|
def words(): |
||||
|
filename = '2013_Wages_for_Facebook_[EN].txt' |
||||
|
path = './manifestos/'+filename |
||||
|
file = open(path, 'r') |
||||
|
manifesto = file.read() |
||||
|
manifesto = manifesto.replace('\n', ' ') |
||||
|
manifesto = manifesto.lower() |
||||
|
manifesto = manifesto.strip() |
||||
|
words = manifesto.split(' ') |
||||
|
new_dict = dict() |
||||
|
|
||||
|
for word in words: |
||||
|
if word in new_dict: |
||||
|
# Present so add 1 to the count of word. |
||||
|
new_dict[word] = new_dict[word] + 1 |
||||
|
else: |
||||
|
# Add the word to dictionary with count 1 |
||||
|
new_dict[word] = 1 |
||||
|
|
||||
|
result = OrderedDict(sorted(new_dict.items(), key=itemgetter(1), reverse=True)) |
||||
|
return result |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
result = words() |
||||
|
print('result:', result) |
Loading…
Reference in new issue