Generation of Combinatorial Objects · Generating Subsets
Lesson 2
Below we will write code together for iterating over different combinatorial objects—such as subsets, permutations, and valid bracket sequences. Each time, we’ll implement the corresponding generator—a function that allows us to iterate over objects one by one, without storing them all in memory.
If you’ve never encountered generators before, please read the corresponding short section of the Python documentation. Make sure you understand what this code will output without running it.
def generate():
yield 2
yield 3
yield 9
for item in generate():
print(item, end=' ')