Created
November 30, 2013 05:22
-
-
Save marcelcaraciolo/7715709 to your computer and use it in GitHub Desktop.
Contador de palavras, baixe a base de: http://www.gutenberg.org/cache/epub/11/pg11.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arq = open('alice.txt') | |
texto = arq.read() | |
texto = texto.lower() | |
import string | |
for c in string.punctuation: | |
texto = texto.replace(c, ' ') | |
texto = texto.split() | |
dic = {} | |
for p in texto: | |
if p not in dic: | |
dic[p] = 1 | |
else: | |
dic[p] += 1 | |
print ('Alice aparece %s vezes' %dic['alice']) | |
arq.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment