Kod
unknown
python
3 years ago
694 B
7
Indexable
#Otwarcie pliku:
file = open(r"C:\Users\Kuba\Desktop\Badanie.txt", "r", encoding='UTF8')
content = file.read()
#Podział tekstu dla słowa:
content_words = content.split(" ")
no_numbers = [word for word in content_words if not any(char.isdigit() for char in word)]
#Zliczanie słów:
counts = {i:no_numbers.count(i) for i in no_numbers}
#Pominięcie słów występujących mniej niż 5 razy:
def filter_infrequent_words(counts, min_occurrences):
frequent_words = {}
for word, count in counts.items():
if count >= min_occurrences:
frequent_words[word] = count
return frequent_words
frequent_words = filter_infrequent_words(counts, 5)
print(frequent_words)Editor is loading...