w3resource

Python: Cut out words of 3 to 6 characters length from a given sentence not more than 1024 characters

Python Basic - 1: Exercise-60 with Solution

Internet search engine giant, such as Google accepts web pages around the world and classify them, creating a huge database. The search engines also analyze the search keywords entered by the user and create inquiries for database search. In both cases, complicated processing is carried out in order to realize efficient retrieval, but basics are all cutting out words from sentences.

Write a Python program to cut out words of 3 to 6 characters length from a given sentence not more than 1024 characters.

Input:
English sentences consisting of delimiters and alphanumeric characters are given on one line.
Output:
Output a word delimited by one space character on one line.

Sample Solution:

Python Code:

print("Input a sentence (1024 characters. max.)")
yy = input()
yy = yy.replace(",", " ")
yy = yy.replace(".", " ")
print("3 to 6 characters length of words:")
print(*[y for y in yy.split() if 3 <= len(y) <= 6])

Sample Output:

Input a sentence (1024 characters. max.)
 The quick brown fox
3 to 6 characters length of words:
The quick brown fox

Pictorial Presentation:

Python: Cut out words of 3 to 6 characters length from a given sentence not more than 1024 characters.
Python: Cut out words of 3 to 6 characters length from a given sentence not more than 1024 characters.

Flowchart:

Flowchart: Python - Cut out words of 3 to 6 characters length from a given sentence not more than 1024 characters

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program that compute the area of the polygon . The vertices have the names vertex 1, vertex 2, vertex 3, ... vertex n according to the order of edge connections.
Next: Write a python program to find heights of the top three building in descending order from eight given buildings.

What is the difficulty level of this exercise?



Inviting useful, relevant, well-written and unique guest posts