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 | Sort tuple list by Nth element of tuple
- Python | Remove tuple from list of tuples if not containing any character
- Python | Count the elements in a list until an element is a Tuple
- Python | Replace tuple according to Nth tuple element
- Python | Remove given element from the list
- Python | Ways to remove particular list element
- Python | Remove random element from list
- Python | Remove given element from list of lists
- Python | Remove element from given list containing specific digits
- Python | Remove Consecutive tuple according to key
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Merge list of tuple into list by joining the strings
- Python | Pair and combine nested list to tuple list
- Python | Convert list to indexed tuple list
- Python | Sort a tuple by its float element
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.