Python Practice › Tuple Programs › Program 33

Tuples with more than 3 elements

EasyTuple Programs · 33 of 70

Write a Python program to keep tuples with more than 3 elements.

Advertisement
Input
[(1, 4), (4, 5, 6), (2,), (7, 6, 8, 9), (3, 5, 6, 0, 1)]
Output
[(7, 6, 8, 9), (3, 5, 6, 0, 1)]

Approach

  1. len(t) > 3.

Solution

Python
data = [(1, 4), (4, 5, 6), (2,), (7, 6, 8, 9), (3, 5, 6, 0, 1)]print([t for t in data if len(t) > 3])
Output
[(7, 6, 8, 9), (3, 5, 6, 0, 1)]
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs