Program to count the elements in a list if an element is a tuple

In this python tuple program, we will count the elements in a list if an element is a tuple.

Steps to solve the program
  1. Take a list as input.
  2. Use a for loop to iterate over each element in the list.
  3. If the type of an element is a tuple then count the number of elements in it and print the output.
  4. Use type() and len() for this purpose.
  5. Print the output.
				
					l = [1,6,8,5,(4,6,8,0),5,4]
print("Original list: ",l)
for val in l:
    if type(val) is tuple:
        print(f"Elements in the tuple {val}: ",len(val))
				
			

Output :

				
					Original list:  [1, 6, 8, 5, (4, 6, 8, 0), 5, 4]
Elements in the tuple (4, 6, 8, 0):  4
				
			

sort a tuple by its float element.

multiply all the elements in a tuple.

Leave a Comment