xs = [2, 7]

import heapq as hq

def closure_gen(xs):
    xs = sorted(set(xs))  # Ensure no duplicates and ascending order
    seen = set(xs)         # Track seen elements to avoid duplicates
    heap = list(xs)        # Initialize the heap with the base elements
    hq.heapify(heap)       # Convert list to a min-heap
    print(heap)
    while heap:
        smallest = hq.heappop(heap)
        yield smallest

        # Generate new products from `smallest` with each element in `xs`
        for x in xs:
            product = smallest * x
            if product not in seen:
                seen.add(product)
                hq.heappush(heap, product)


g = closure_gen(xs)
for i in range(100):
    r = next(g)
    print(i, r)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: