Python tuple program to find tuples having negative elements in it

In this python tuple program, we will find tuples having negative elements in it.

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 any() function with an if statement to check whether elements in the tuples are negative.
  4. 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)
				
			

find all the tuples that are divisible by a number.

find the tuples with positive elements.

Leave a Comment