Python Practice › List Programs › Program 64

Strings of a given length

EasyList Programs · 64 of 100

Write a Python program to extract the strings of a given length.

Advertisement
Input
["Python", "Sqatools", "Practice", "Program", "test", "list"], size 8
Output
['Sqatools', 'Practice']

Approach

  1. Filter by len().

Solution

Python
words = ["Python", "Sqatools", "Practice", "Program", "test", "list"]print([w for w in words if len(w) == 8])
Output
['Sqatools', 'Practice']

Learn the concept

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

More list programs

← All 100 List Programs

Leave a Comment