Write a python function to filter Rows with a specific pair sum and return boolean value
Topic: Write a python function to filter Rows with a specific pair sum and return boolean value
Solution
def pair_sum(x, k): # checking pair sum for idx in range(len(x)): for ix in range(idx + 1, len(x)): if x[idx] + x[ix] == k: return True return False test_list = [[1, 5, 3, 6], [4, 3, 2, 1], [7, 2, 4, 5], [6, 9, 3, 2]] print("The original list is : " + str(test_list)) k = 8 res = [ele for ele in test_list if pair_sum(ele, k)] print("Filtered Rows : " + str(res))
List all Python Programs