In this python tuple program, we wil remove tuples of length i.
Steps to solve the program
- Take a list of tuples as input.
- Use for loop to iterate over each tuple in the list.
- If the length of the tuple is equal to 2 then remove that tuple from the list using remove().
- 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.