Python tuple program to find the tuples with positive elements

In this python tuple program, we will find the tuples with positive elements.

Steps to solve the program
  1. Take a list of tuples as input.
  2. Use a for loop to iterate over tuples in the list.
  3. Use an if statement with any() function to find the tuples having positive elements in them.
  4. 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)
				
			

find tuples having negative elements.

remove duplicates from a tuple.

Leave a Comment