w3resource logo
Python Exercises

Python Exercise: Remove an empty tuple(s) from a list of tuples

Python tuple: Exercise-22 with Solution

Write a Python program to remove an empty tuple(s) from a list of tuples.

Sample Solution:-

Python Code:

L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
L = [t for t in L if t]
print(L)

Sample Output:

[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']  

Python Code Editor:

L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
L = [t for t in L if t]
print(L)

Improve this sample solution and post your code through Disqus