Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import permutations as perm
- def closest_to_zero(arr):
- L1, D1, found = perm(arr, 2), dict(), False
- for i in L1:
- D1[sum(i)] = i
- L2 = [abs(i) for i in D1.keys()]
- req_val = min(L2)
- while not found:
- res_T1 = D1.get(req_val, "")
- if any(res_T1):
- return res_T1
- else:
- req_val = -req_val
- return res_T1
- var = closest_to_zero([10,20,30,40,50,60,-1,-2,-3,-4,-5,-6])
- print(var)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement