L
L
lilandre22016-08-20 15:09:11
Python
lilandre2, 2016-08-20 15:09:11

How to find the most used words in a book using python?

There is a book in TXT format. It is required to find the frequency of the words used and save the first 1000 words to a file. I can not understand in which direction I should dig. While studying https://courses.edx.org/courses/course-v1:Microsof... .

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Roman Kitaev, 2016-08-20
@lilandre2

from collections import Counter
x = open('Война и мир.txt', encoding='utf8').read()
c = Counter(x.split())  # Сплит нужен, чтобы вышел список слов, иначе посчитаем частотность символов
c.most_common()

Владимир Мартьянов, 2016-08-20
@vilgeforce

Копайте в сторону словарей в Питоне, например.

D
D', 2016-08-20
@Denormalization

nlpx.net/archives/29 раздел "Частотный анализ", оно?

V
Vitaly, 2016-08-20
@vt4a2h

Make a map where the key is the word and the value is the frequency. Each time a word occurs, increase the frequency by 1. Then take the 1000 maximum frequencies and output the keys to a file. That's all.

C
crawlander, 2016-08-20
@crawlander

Based on this program, you can finish https://en.wikiversity.org/wiki/%D0%9F%D1%80%D0%B8...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question