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, howev
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 trappe
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 th
Michael Spencer 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 implementation:
>>>
>>> def join(sep,
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
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 implementation:
>>
>>def join(sep, seq):
>>if len(seq):
>>r
"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
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(*
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
> 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.
--
ht
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:
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):
>
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
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()
14 matches
Mail list logo