1. [20 points] Counting Duplicate Words Write a script that uses a dictionary to determine and print the number of duplicate words in a sentence. Treat uppercase and lowercase letters the same and assume there is no punctuation in the sentence. Words with counts larger than 1 have duplicates. Use the following sentence to test your code: text = ('this is sample text with several words' 'this is more sample text with some different words') Your output for this sentence should look something like the following: WORD COUNT is 2 sample 2 text 2 this 2 with 2 words 2
Added by Esperanza V.
Close
Step 1
First, we need to remove any punctuation from the sentence. We can use the `string` module to get a string of all punctuation characters and then use the `translate()` method to remove them from the sentence. Show more…
Show all steps
Your feedback will help us improve your experience
Brooke Bussoletti and 82 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
write a python program to find most frequent words in the text
Akash M.
Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. For coding simplicity, follow each output word by a comma, even the last one. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words.
James K.
Write a method/function called bigwords() to read the contents from a text file code.txt and count and display the occurrence of words that have 5 or more alphabets in Python 12th class.
Liam H.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD