Python Practice › String Programs › Program 46

Words longer than n characters

EasyString Programs · 46 of 106

Write a Python program to find the words longer than a given length.

Advertisement
Input
length = 3, text = "We are learning python"
Output
learning python

Approach

  1. Filter words by len(w) > n.

Solution

Python
n = 3text = "We are learning python"print(" ".join(w for w in text.split() if len(w) > n))
Output
learning python
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs