Example:
tuple = ("python", "includehelp", 43, 54.23)
Filtering tuples according to list element
We are given a list of tuples and a list consisting of integer elements. We need to create a Python program to filter tuples that contain elements that are present in the list.
Input:
[(2, 9) ,(5, 6), (1, 3), (4, 8)]
[2, 3]
Output:
[(2, 9), (1, 3)]
Method 1:
One direct method is to use list comprehension to perform the iteration of the tuple of the list and check for the presence of elements in the list and filter based on it.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer