Lab 5
Topic: Map (Python)
Write a program that asks the user to enter English words. The program then prints the words and the number of time they appear. You probably will want to change all the words to lower case before doing anything with them. See sample run below. The green text is what the user typed in.
Sample run:
Enter English words: The most important thing is to find
out
what is the most important thing.
Word Count
the 2
most 2
thing 2
is 2
find 1
out 1
what 1
s = input('Enter English words: ') # The most important thing is to find out what is the most important thing. counts = {} s = s.lower() for word in s.split(): counts[word] = 1 + counts.get(word, 0) for (w, c) in counts.items(): print('%-10s%d' % (w, c))
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Get Answers For Free
Most questions answered within 1 hours.