In this python tuple program, we will find tuples having negative elements in it.
Steps to solve the program
- Take a list of tuples as input.
- Use a for loop to iterate over tuples in the list.
- Use any() function with an if statement to check whether elements in the tuples are negative.
- Print such tuples.
l = [(1,7),(-4,-5),(0,6),(-1,3)]
for tup in l:
if any(ele < 0 for ele in tup):
print("Tuple having negative element: ",tup)
Output :
Tuple having negative element: (-4, -5)
Tuple having negative element: (-1, 3)