Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created November 30, 2013 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelcaraciolo/7715709 to your computer and use it in GitHub Desktop.
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
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