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

Explain how action research by the teachers in class helps in effective teaching and improved learning outcomes

NIU - NUR International University - Admission Process

Pakistan Television Corporation ( PTV ) New Jobs 2025

Dengue Fever: Comprehensive Guide on Prevention, Treatment, and Health Guidelines

Government University and Collage Faisalabad ( GCUF ) Admission Criteria All Departments

Irrigation Department Bahawalpur Canal Division Jobs 2025

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

Calculate and print each student average using Python

Data Analyst Environment Protection and Climate Change Department Jobs 2025

Indian BSF soldier arrested on Pakistani soil by Pak Rangers