Python Challenge | Word Frequency

preview_player
Показать описание
Welcome to Python code challenges. In this Python code challenge series we hope to compliment the existing Python courses on this channel. Code challenges are for people looking to sharpen their Python skills first at a beginner's level with the ambition to then move into more advanced challenges as we progress.

Code Challenge:
Write a programme that counts the frequency of all words from a given input

Code Repository:
Рекомендации по теме
Комментарии
Автор

If you want to sort by the count and not the keys.
# ascending
sorted_by_count = dict(sorted(frequency.items(), key=lambda count: count[1])
# descending
sorted_by_count = dict(sorted(frequency.items(), key=lambda count: count[1], reverse=True)

for word, count in sorted_by_count.items():
print(f"{word} = {count}")

qman
Автор

x=input()
fre={}
for i in x.split():
fre[i] = x.count(i)
print(fre)

chandramouli
Автор

Within for loop body, I used a try-except block like:
try:
frequency [word] += 1
except:
frequency [word] = 1

abhishektayal
Автор

you should use Counter available in the collections and pass the list to it.

MohdTalib-ymwb
Автор

It breaks if a sentence contains some word just before a comma or any other symbol.
"Hary, John and Hary live in same town"

santoshbhattarai
Автор

How do you configure to get email in var? It looks quite interesting

treblaoj
welcome to shbcf.ru