def allpairs(arr, target):
    for i, js in findpairs(arr, target):
        for j in js:
            if i < j:
                yield i, j
Better algorithm (than using a dict) for enumerating pairs with a given sum.