Python Practice › Tuple Programs › Program 33
Tuples with more than 3 elements
Write a Python program to keep tuples with more than 3 elements.
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
len(t) > 3.
Solution
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)]
Learn the concept
New to this topic? Read the lesson, then come back.