Enumerating all 3-tuples (Posting On Python-List Prohibited)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue Mar 13 07:10:40 EDT 2018
On Sun, 11 Mar 2018 01:40:01 +0000, Ben Bacarisse wrote:
> I'm sure deep recursion is not needed, it's just tricky translating from
> a lazy language when one is not familiar with all the iterator
> facilities in Python. For example, I couldn't find an append operation
> that returns an iterable.
The Python iterator protocol is intentionally lightweight, so there's no
"append" operation and + is not supported.
But you can call
it = itertools.chain(it, iterator2)
It's not often that I think Ruby's ability to monkey-patch arbitrary
objects including built-ins is a good idea, but the ability to allow
iterator+iterator is *almost* one of those times.
--
Steve
More information about the Python-list
mailing list