I have three sorted lists, examplewise
a, b, c = [10,9,8], [9,8,7], [13,5,1]
I want to get all the combinations x, y, z where x in a, y in b and z in c and 1/x + 1/y + 1/z < 1 in the fastest time possible. I've been trying some different approaches,
for x, y, z in product(a, b, c):
if predicative(x,y,z):
yield (x, y, z)
Obviously, this takes too long time considering I'm checking everything, and the lists a, b, c are already sorted. I have tried sorting product(a,b,c) on the sum, but that is reaaally slow, as it uses all the products. My initial plan with having a, b and c sorted is so I could break out of the loop as soon as one fails. Any ideas?
Thanks.
itertools.takewhile? The pure Python equivalent implementation is effectively your current approach plus two lines (else: break).takewhile willwork to be honest, as it goes linearly through. The wayproductis sorted, I could easily miss combinations. Please correct me if I'm wrong.