Re: Feature Proposal: Sequence .join method

2005-10-08 Thread Alex Martelli
Michele Simionato [EMAIL PROTECTED] wrote: ... 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

Re: Feature Proposal: Sequence .join method

2005-09-30 Thread Terry Reedy
David Murmann [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] def join(sep, seq): return reduce(lambda x, y: x + sep + y, seq, type(sep)()) damn, i wanted too much. Proper implementation: def join(sep, seq): if len(seq): return reduce(lambda x, y: x + sep + y,

Re: Feature Proposal: Sequence .join method

2005-09-30 Thread Jp Calderone
On Fri, 30 Sep 2005 09:38:25 -0700, Michael Spencer [EMAIL PROTECTED] wrote: Terry Reedy wrote: David Murmann [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] def join(sep, seq): return reduce(lambda x, y: x + sep + y, seq, type(sep)()) damn, i wanted too much. Proper

add keyword argument to itertools.chain [was Feature Proposal: Sequence .join method]

2005-09-30 Thread David Murmann
Hi again, i wrote a small patch that changes itertools.chain to take a link keyword argument. If given, it is iterated between the normal arguments, otherwise the behavior is unchanged. I'd like to hear your opinion on both, the functionality and the actual implementation (as this is one of the

Feature Proposal: Sequence .join method

2005-09-29 Thread David Murmann
Hi all! I could not find out whether this has been proposed before (there are too many discussion on join as a sequence method with different semantics). So, i propose a generalized .join method on all sequences with these semantics: def join(self, seq): T = type(self) result = T()

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread David Murmann
David Murmann wrote: replace the line result = result + self + T(item) with result = result + self + item and of course the line result = T(seq[0]) with result = seq[0] -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread Steven Bethard
David Murmann wrote: Hi all! I could not find out whether this has been proposed before (there are too many discussion on join as a sequence method with different semantics). So, i propose a generalized .join method on all sequences with these semantics: def join(self, seq): T =

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread David Murmann
Steven Bethard wrote: David Murmann wrote: Hi all! I could not find out whether this has been proposed before (there are too many discussion on join as a sequence method with different semantics). So, i propose a generalized .join method on all sequences with these semantics: def

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread David Murmann
def join(sep, seq): return reduce(lambda x, y: x + sep + y, seq, type(sep)()) damn, i wanted too much. Proper implementation: def join(sep, seq): if len(seq): return reduce(lambda x, y: x + sep + y, seq) return type(sep)() but still short enough see you, David. --

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread Fredrik Lundh
David Murmann wrote: I could not find out whether this has been proposed before (there are too many discussion on join as a sequence method with different semantics). So, i propose a generalized .join method on all sequences so all you have to do now is to find the sequence base class, and

Re: Feature Proposal: Sequence .join method

2005-09-29 Thread en.karpachov
On Thu, 29 Sep 2005 20:37:31 -0600 Steven Bethard wrote: I don't like the idea of having to put this on all sequences. If you want this, I'd instead propose it as a function (perhaps builtin, perhaps in some other module). itertools module seems the right place for it. itertools.chain(*a)