Generator chaining?

J

John Doe

This is sort of a feature request/idea: Chaining generators.

If you have two lists (or tuples) and you add them, the result is a
concatenation of the two.
I think it would be nice if it was possible to do something similar with
generators. The best way to explain is by code example:

def add_generators(gen1, gen2):
for x in gen1:
yield x
for y in gen2:
yield y

Just a thought...
 
D

Duncan Booth

John said:
This is sort of a feature request/idea: Chaining generators.

If you have two lists (or tuples) and you add them, the result is a
concatenation of the two.
I think it would be nice if it was possible to do something similar with
generators. The best way to explain is by code example:

def add_generators(gen1, gen2):
for x in gen1:
yield x
for y in gen2:
yield y

Just a thought...

itertools.chain
 
G

Gabriel Genellina

This is sort of a feature request/idea: Chaining generators.

If you have two lists (or tuples) and you add them, the result is a
concatenation of the two.
I think it would be nice if it was possible to do something similar with
generators. The best way to explain is by code example:

Already done: itertools.chain



Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top