-
-
Save filipecifali/84df2e7b0a04bd6253ad59ece63014ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
""" | |
Autor: [email protected] | |
Modulo builtin disponivel no core | |
https://docs.python.org/3/library/collections.html?highlight=counter#collections.Counter | |
""" | |
from collections import Counter | |
# declarar a lista para preencher ela com todas as palavras do arquivo | |
words = [] | |
# usando with open ele mantem o arquivo aberto somente pela iteração do loop | |
with open('t.txt', 'r') as f: | |
# para cada linha lida executar a adição na lista | |
for line in f.readlines(): | |
# rstrip remove a quebra de linha para não poluir a string que é armazenada na lista | |
words.append(line.rstrip('\n')) | |
# Majicks | |
c = Counter(words) | |
print("Top ocorrências: ", c.most_common(3)) | |
print("Lista completa:", c) |
This file contains hidden or 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
string1 | |
string3 | |
string3 | |
string2 | |
string1 | |
string2 | |
string2 | |
string1 | |
string3 | |
string3 | |
string1 | |
string3 | |
string4 | |
string2 | |
string4 | |
string1 | |
string4 | |
string2 | |
string1 | |
string2 | |
string1 | |
string3 | |
string1 | |
string3 | |
string1 | |
string3 | |
string4 | |
string3 | |
string3 | |
string1 | |
string1 | |
string4 | |
string4 | |
string1 | |
string1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment