The program is written in Python and performs the following operations:
The final output of the program will be the nearest tuple from the list "val" with respect to the first index (K = 1) of the tuple "t".
val = [(23, 18), (9, 2), (2, 3), (9, 18), (23, 2)] print("List : " ,val) t = (20, 2) K = 1 res = min(range(len(val)), key = lambda sub: abs(val[sub][K - 1] - t[K - 1])) print("Nearest Tuple : " ,val[res])
List : [(23, 18), (9, 2), (2, 3), (9, 18), (23, 2)] Nearest Tuple : (23, 18)
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions