The program filters a list of tuples based on the values in a given list and returns a new list of tuples that meet a specific criteria. Here's what happens step-by-step:
So the program filters the original val list based on the values present in the l list and returns a new list of tuples that meet the criteria.
val = [('B', 68), ('D', 70), ('A', 67), ('C', 69)] print("The original list is : " + str(val)) l = [67 , 70 , 71, 75] K = 1 res = [s for s in val if s[K] in l] print("The filtered tuples : " + str(res))
The original list is : [('B', 68), ('D', 70), ('A', 67), ('C', 69)] The filtered tuples : [('D', 70), ('A', 67)]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions