Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pairs(ints, target, result=None):
- if result is None:
- result = []
- first = ints.pop(0)
- remain = target - first
- if remain in ints:
- result.append((first, remain))
- ints.remove(remain)
- if (len(ints) > 1):
- pairs(ints, target, result)
- return result
- pairs([1, 2, 3, 4], 5) # [(1, 4), (2, 3)]
- pairs([1, -2, 5, 4, 7], 5) # [(1, 4), (-2, 7)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement