Python Practice › Tuple Programs › Program 47
Tuples whose items are all divisible by 5
Write a Python program to find the tuples whose elements are all divisible by a number.
Input
[(10, 5, 15), (25, 6, 35), (20, 10)], number 5
Output
[(10, 5, 15), (20, 10)]
Approach
all(x % k == 0 for x in t).
Solution
data = [(10, 5, 15), (25, 6, 35), (20, 10)]k = 5print([t for t in data if all(x % k == 0 for x in t)])Output
[(10, 5, 15), (20, 10)]
Learn the concept
New to this topic? Read the lesson, then come back.