Remove Empty Tuples from a List Python (original) (raw)

Last Updated : 1 Nov, 2025

Given a list that contains both empty and non-empty tuples, the task is to remove all empty tuples from the list. **For Example:

**Input: [(1, 2), (), (3, 4), (), (5,)]
**Output: [(1, 2), (3, 4), (5,)]

Let’s explore different methods to remove empty tuples from a list in Python.

Using List Comprehension

List comprehension provides a concise way to filter elements. It iterates through the list and includes only tuples that evaluate to True.

Python `

a = [(1, 2), (), (3, 4), (), (5,)] res = [t for t in a if t] print(res)

`

Output

[(1, 2), (3, 4), (5,)]

**Explanation :

Using filter()

The filter() function removes elements that are falsy when the first argument is None.

Python `

a = [(1, 2), (), (3, 4), (), (5,)] res = list(filter(None, a)) print(res)

`

Output

[(1, 2), (3, 4), (5,)]

**Explanation:

compress() allows filtering based on a boolean mask, which is constructed using the truth value of each tuple.

Python `

from itertools import compress

a = [(1, 2), (), (3, 4), (), (5,)] res = list(compress(a, [bool(t) for t in a])) print(res)

`

Output

[(1, 2), (3, 4), (5,)]

**Explanation:

Using a For Loop

This basic approach removes empty tuples from a list using a for loop and append(). It checks each tuple and appends only non-empty tuples to a new list.

Python `

a = [(1, 2), (), (3, 4), (), (5,)] res = []

for t in a: if t: res.append(t) print(res)

`