Python Practice › Tuple Programs › Program 47

Tuples whose items are all divisible by 5

EasyTuple Programs · 47 of 70

Write a Python program to find the tuples whose elements are all divisible by a number.

Advertisement
Input
[(10, 5, 15), (25, 6, 35), (20, 10)], number 5
Output
[(10, 5, 15), (20, 10)]

Approach

  1. all(x % k == 0 for x in t).

Solution

Python
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)]
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs