Python Practice › Tuple Programs › Program 27

Remove tuples containing None

EasyTuple Programs · 27 of 70

Write a Python program to remove tuples that contain None.

Advertisement
Input
[(None, 2), (None, None), (5, 4), (1, 6, 7)]
Output
[(5, 4), (1, 6, 7)]

Approach

  1. Keep tuples where None not in t.

Solution

Python
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)]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs