9bb2630587
Signed-off-by: Robert Nedela <robertnedela15@gmail.com>
26 lines
537 B
Python
26 lines
537 B
Python
import string
|
|
|
|
with open("fisier.txt", "r") as file:
|
|
text = file.read()
|
|
|
|
text = text.lower()
|
|
|
|
for semn in string.punctuation:
|
|
text = text.replace(semn, " ")
|
|
|
|
# frecventa cuvinte
|
|
cuvinte = text.split()
|
|
frec = {}
|
|
for cuv in cuvinte:
|
|
if cuv in frec:
|
|
frec[cuv] = frec[cuv] + 1
|
|
else:
|
|
frec[cuv] = 1
|
|
|
|
cuv_sort = sorted(frec.items(), key=lambda x: x[1], reverse=True)
|
|
for i in range(5):
|
|
if i < len(cuv_sort):
|
|
cuv = cuv_sort[i][0]
|
|
numar = cuv_sort[i][1]
|
|
print(f"'{cuv}' : {numar}")
|