From aa6a2d96f3ddfb0f851e9cfa697741eecac5f977 Mon Sep 17 00:00:00 2001 From: SUHAS M <65087769+suhasmj@users.noreply.github.com> Date: Sat, 9 Oct 2021 00:52:56 +0530 Subject: [PATCH] Create dictionary_frequency.py --- py/dictionary_frequency.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 py/dictionary_frequency.py diff --git a/py/dictionary_frequency.py b/py/dictionary_frequency.py new file mode 100644 index 000000000..9c732b0d0 --- /dev/null +++ b/py/dictionary_frequency.py @@ -0,0 +1,13 @@ +def word_count(str): + counts = dict() + words = str.split() + + for word in words: + if word in counts: + counts[word] += 1 + else: + counts[word] = 1 + return counts + +sentence = input("enter sentence: ") +print( word_count(sentence))