Example:
tuple = ("python", "includehelp", 43, 54.23)
Getting Records with Value at K index
In this program, we are given a list of tuples and two integer value elements, and index k. We will be creating a python program to get records with value at k index.
Input:
[(5, 7), (4, 8, 3, 1), (5, 8, 0), (1, 2, 3, 4, 5, 7)]
ele = 8, k = 2
Output:
[(4, 8, 3, 1), (5, 8, 0)]
Method 1:
One method to solve the problem is by using a direct approach where we will traverse the list and check if the given element is present at the specific index k.
Output:
Method 2:
Another method to solve the problem is by enumeration of indexes and then comparing the element for the given index. To perform the task in a single line of code, we will be using list comprehension.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer