Discussions Events Study Material Jobs
Create a Frequency Dictionary from a Sentence using Python - Uniwaly

Explore Diverse Conversations

Create a Frequency Dictionary from a Sentence using Python

Posted By: UmairMehmood Published On: 13 June 2025 At: 12:30 PM

Input a sentence from the user and count the frequency of each word using a dictionary.
sentence = input("Enter a sentence: ")
words = sentence.split()
frequency = {}
for word in words:
    if word in frequency:
        frequency[word] += 1
    else:
        frequency[word] = 1
print("\nWord Frequency:")
for word in frequency:
    print(f"{word}: {frequency[word]}")


Output:

Enter a sentence: hello iam here

Word Frequency:
hello: 1
iam: 1
here: 1

Process finished with exit code 0


Tags:

python frequency dictionary python code
Login to like

Posted By:

Author Profile

UmairMehmood

11 days ago

Join the conversation!

Login to Comment

Discover More Articles

How to Attestation of Degrees/Diplomas/Certificates From HEC ?

CM Punjab Asaan Karobaar Card Scheme

University of Veterinary & Animal Sciences UVAS Swat

Compare the teacher education reforms in developed and developing countries.

Warning! Avoid Fraudulent Job Offers

Virtual University of Pakistan Admission Process

Merge Two Dictionaries using Python

Palm Reading in Islam : Is It Permissible? A Faith-Centered Guide

Understanding the HTML Boilerplate: A Comprehensive Guide to the Basics of Web Development

Input marks and print grade using conditions in Python