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

Write a program to calculate the sum of all elements in a list using a for loop using Python

How to Keep a Camera Stream Active Across Pages Without Reinitializing the Camera on Each Page?

Input a list and create a dictionary where keys are elements and values are their frequency using Python

Divisional Manager - The Urban Unit Jobs 2025

Use a nested dictionary of students and their subject marks Using Python

Graphic Designer Jobs in Forest Department , PAKISTAN 2025

Essential Timeline of British India: Pivotal Events Leading to Independence

Communication & Coordination Officer - The Urban Unit Jobs 2025

National University of Computer and Emerging Sciences Admission Process

پاکستانی ڈاکٹر کو کینیڈا کے بڑے سول اعزاز 'آرڈر آف کینیڈا "سے نواز دیا گیا