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