Generators

sage.combinat.generator.concat(gens)

Returns a generator that is the concatenation of the generators in the list.

EXAMPLES:

sage: list(sage.combinat.generator.concat([[1,2,3],[4,5,6]]))
[1, 2, 3, 4, 5, 6]
sage.combinat.generator.element(element, n=1)

Returns a generator that yield a single element n times.

EXAMPLES:

sage: list(sage.combinat.generator.element(1))
[1]
sage: list(sage.combinat.generator.element(1, n=3))
[1, 1, 1]
sage.combinat.generator.map(f, gen)

Returns a generator that returns f(g) for g in gen.

EXAMPLES:

sage: f = lambda x: x*2
sage: list(sage.combinat.generator.map(f,[4,5,6]))
[8, 10, 12]
sage.combinat.generator.select(f, gen)

Returns a generator for all the elements g of gen such that f(g) is True.

EXAMPLES:

sage: f = lambda x: x % 2 == 0
sage: list(sage.combinat.generator.select(f,range(7)))
[0, 2, 4, 6]
sage.combinat.generator.successor(initial, succ)

Given an initial value and a successor function, yield the initial value and each following successor. The generator will continue to generate values until the successor function yields None.

EXAMPLES:

sage: f = lambda x: x+1 if x < 10 else None
sage: list(sage.combinat.generator.successor(0,f))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Previous topic

Tools

Next topic

Rankers

This Page