In this python tuple program, we will remove tuples from the List having an element as None.
Steps to solve the program
- Take a list of tuples as input.
- Use for loop to iterate over tuples in the list.
- Use another nested loop to iterate over elements in the tuples.
- In an element in the tuple is equal to None then remove that tuple from the list.
- Print the output.
l = [(None,),(5, 4),(1,6,7),(None,1)]
print("Origianl list: ",l)
for tup in l:
for ele in tup:
if ele == None:
l.remove(tup)
print("After removing tuples: ",l)
Output :
Origianl list: [(None,), (5, 4), (1, 6, 7), (None, 1)]
After removing tuples: [(5, 4), (1, 6, 7)]