Files
Robert Nedela 9bb2630587 Primul commit si adaugat primu lab
Signed-off-by: Robert Nedela <robertnedela15@gmail.com>
2026-03-10 17:50:00 +02:00

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}")