Python Practice › Tuple Programs › Program 49

Tuples with no negative elements

EasyTuple Programs · 49 of 70

Write a Python program to find tuples whose elements are all zero or positive.

Advertisement
Input
[(1, 7), (-4, -5), (0, 6), (-1, 3)]
Output
[(1, 7), (0, 6)]

Approach

  1. all(x >= 0 for x in t).

Solution

Python
data = [(1, 7), (-4, -5), (0, 6), (-1, 3)]print([t for t in data if all(x >= 0 for x in t)])
Output
[(1, 7), (0, 6)]
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs