Python Practice › Tuple Programs › Program 27
Remove tuples containing None
Write a Python program to remove tuples that contain None.
Input
[(None, 2), (None, None), (5, 4), (1, 6, 7)]
Output
[(5, 4), (1, 6, 7)]
Approach
- Keep tuples where
None not in t.
Solution
data = [(None, 2), (None, None), (5, 4), (1, 6, 7)]print([t for t in data if None not in t])Output
[(5, 4), (1, 6, 7)]
Learn the concept
New to this topic? Read the lesson, then come back.