Python Practice › Tuple Programs › Program 48
Tuples with a negative element
Write a Python program to find tuples that contain at least one negative number.
Input
[(1, 7), (-4, -5), (0, 6), (-1, 3)]
Output
[(-4, -5), (-1, 3)]
Approach
any(x < 0 for x in t).
Solution
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)]
Learn the concept
New to this topic? Read the lesson, then come back.