Since the advent of popularity of Python in data analysis, we have list of tuples as a container in many of our problems. Sometimes, while data preprocessing, we might have a problem in which we need to completely remove a particular element from a list of tuple. Let’s discuss a way in which this task can be performed.
Method : Using list comprehension
This task can be used using brute force manner using loop, but a better alternative shorthand would be an approach which could perform this task in one line. List comprehension can help us achieve it and hence it’s recommended to use this method to perform this task. This just checks for element and removes if it’s the selected element.
The original list is : [(5, 6, 7), (7, 2, 4, 6), (6, 6, 7), (6, 10, 8)] The Tuple List after removal of element : [(5, 7), (7, 2, 4), (7, ), (10, 8)]
- Python | Remove duplicates based on Kth element tuple list
- Python | Sort tuple list by Nth element of tuple
- Python | Remove similar element rows in tuple Matrix
- Python | Remove tuple from list of tuples if not containing any character
- Python | Maximum element in tuple list
- Python - Concatenate Kth element in Tuple List
- Python | Minimum element in tuple list
- Python | Update each element in tuple list
- Python | Count the elements in a list until an element is a Tuple
- Python | Remove given element from the list
- Python | Ways to remove particular list element
- Python | Remove random element from list
- Python - Remove rear element from list
- Python | Remove given element from list of lists
- Python | Remove element from given list containing specific digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.