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

Pension New Method Explained - Which Employees Not Eligible For Pension ?

Voting Eligibility Checker Using Python

New 30,000 Teaching Jobs Coming Soon on Merit : CM Punjab

Charge Your Electric Car Just in 5 Minutes - New Achievement

Describe in the light of Paget’s theory the cognitive and intellectual development of a child at different levels.

Visiting / Teaching Faculty Jobs in University of Veterinary and Animal Sciences Lahore 2025

Urban Unit Official Training Confirmation Email & Dates 2025

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

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

Input 5 numbers from the user and store them in a list. Then print the list Using Python