Python Practice › Tuple Programs › Program 48

Tuples with a negative element

EasyTuple Programs · 48 of 70

Write a Python program to find tuples that contain at least one negative number.

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

Approach

  1. any(x < 0 for x in t).

Solution

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

Learn the concept

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

More tuple programs

← All 70 Tuple Programs