Feature Proposal: Sequence .join method

Michele Simionato michele.simionato at gmail.com
Sat Oct 1 02:16:25 EDT 2005


This can be shortened to

def interlace(x, i):
        """interlace(x, i) -> i0, x, i1, x, ..., x, iN
        """
        i = iter(i)
        i.next()
        for e in i:
            yield x
            yield e

I have noticed a while ago that inside generators StopIteration is
automatically trapped, i.e.

def g():
    yield 1
    raise StopIteration
    yield "Never reached"

only yields 1. Not sure if this is documented behavior, however, of if
it is an implementation
accident. Anybody who knows?

                    Michele Simionato




More information about the Python-list mailing list