Python tuple program to remove tuples of length i

In this python tuple program, we wil remove tuples of length i.

Steps to solve the program
  1. Take a list of tuples as input.
  2. Use for loop to iterate over each tuple in the list.
  3. If the length of the tuple is equal to 2 then remove that tuple from the list using remove().
  4. Print the output.
				
					list1 = [(2,5,7),(3,4),(8,9,0,5)]
print("Original list: ",list1)
for tup in list1:
    if len(tup) == 2:
        list1.remove(tup)
        
print("After removing tuple having length 2: ",list1)
				
			

Output :

				
					Original list:  [(2, 5, 7), (3, 4), (8, 9, 0, 5)]
After removing tuple having length 2:  [(2, 5, 7), (8, 9, 0, 5)]
				
			

remove tuples from the List having an element as None.

Leave a Comment