Python: Find the string consisting of all the words whose lengths are prime numbers
Words with Prime Lengths
Write a Python program to find the string consisting of all the words whose lengths are prime numbers.
Input: The quick brown fox jumps over the lazy dog. Output: The quick brown fox jumps the Input: Omicron Effect: Foreign Flights Won't Resume On Dec 15, Decision Later. Output: Omicron Effect: Foreign Flights Won't On Dec 15,
Visual Presentation:

Sample Solution:
Python Code:
Sample Output:
Original list of numbers: The quick brown fox jumps over the lazy dog. Words whose lengths are prime numbers in the said string: The quick brown fox jumps the Original list of numbers: Omicron Effect: Foreign Flights Won't Resume On Dec 15, Decision Later. Words whose lengths are prime numbers in the said string: Omicron Effect: Foreign Flights Won't On Dec 15,
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to extract words from a sentence whose lengths are prime numbers and join them into a new string.
- Write a Python program to filter words in a given text to include only those with prime-number lengths using a helper prime-check function.
- Write a Python program to iterate over a list of words and return a list of words that have prime lengths.
- Write a Python program to use regular expressions to validate word lengths and select those with prime counts.
Go to:
Previous: Find the sum of the even elements that are at odd indices in a given list.
Next: Circular shift number.
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.