Python Practice › String Programs › Program 46
Words longer than n characters
Write a Python program to find the words longer than a given length.
Input
length = 3, text = "We are learning python"
Output
learning python
Approach
- Filter words by
len(w) > n.
Solution
n = 3text = "We are learning python"print(" ".join(w for w in text.split() if len(w) > n))Output
learning python
Learn the concept
New to this topic? Read the lesson, then come back.