pq = [(prob(x), x) for x in items]
yield ()
while pq:
    p, x = heappop(pq)
yield x
for other in ps:
    if other < x[-1]:
        new = x + (other,)
item = prob(new), new
heappush(pq, item)
a = [1, 0.1, 0.5]
print(list(gen(a)))
Algorithm to get every possible subset of a list, in order of their product, without building and sorting the entire list (i.e Generators)