Skip to content

案例:数词频

Cheng-Jun Wang edited this page Sep 26, 2019 · 1 revision

数词频

https://plato.stanford.edu/entries/socrates/

with open('socrates.txt', 'r') as f:
    lines = f.readlines()

story  = ' '.join(lines)
story = story.replace('\n', '').replace('.', '').replace("’", '').replace(',', '').replace(':', '').replace('?', '')
story_list = story.split(' ')
word_dic = {i:0 for i in story_list}

for i in story_list:
    word_dic[i] +=1
Clone this wiki locally