Re: Feature Proposal: Sequence .join method
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Feature Proposal: Sequence .join method

From: Michele Simionato <michele.simionato@gmail.com>
Date: Sat Oct 01 2005 - 08:16:25 CEST

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
Received on Sat Oct 15 04:01:54 2005