The topic reminded me of Stephan Houben's streamtee.
https://github.com/stephanh42/streamtee/blob/master/streamtee.py
It was an attempt at a memory-efficient tee, but it turned out tee was
efficient enough. It uses a thunk-like method and recursion to remove
the need for an explicit linked list.
I posted this several weeks ago, just for fun - an obscure but
surprisingly brief Python implementation of itertools.tee, sharing a
single stream (as a singly linked list) among all the returned
iterables.
Didn't think about it again until today, when recent discussions of
lexical scoping made me
On Sun, Apr 15, 2018 at 08:35:51PM +0300, Serhiy Storchaka wrote:
> I have ideas about implementing zero-overhead try/except, but I have
> doubts that it is worth. The benefit seems too small.
It is conventional wisdom that catching exceptions is expensive, and
that in performance critical
On Sun, Apr 15, 2018 at 11:55 PM, Chris Angelico wrote:
> On Mon, Apr 16, 2018 at 6:46 AM, Koos Zevenhoven
> wrote:
> > Anyway, the whole linked list is unnecessary if the iterable can be
> iterated
> > over multiple times. But "tee" won't know when to do
On Mon, Apr 16, 2018 at 12:06 AM, Tim Peters wrote:
> [Koos Zevenhoven ]
> > It's definitely possible to write the above in a more
> > readable way, and FWIW I don't think it involves "assignments as
> > expressions".
>
> Of course it is. The point
[Koos Zevenhoven ]
> It's definitely possible to write the above in a more
> readable way, and FWIW I don't think it involves "assignments as
> expressions".
Of course it is. The point was brevity and speed, not readability.
It was presented partly as a puzzle :-)
>> What
On Mon, Apr 16, 2018 at 6:46 AM, Koos Zevenhoven wrote:
> Anyway, the whole linked list is unnecessary if the iterable can be iterated
> over multiple times. But "tee" won't know when to do that. *That* is what I
> call overhead (unless of course all the tee branches are
On Sun, Apr 15, 2018 at 8:05 AM, Tim Peters wrote:
[...]
> Then I thought "this is stupid! Python already does reference
> counting." Voila! Vast swaths of tedious code vanished, giving this
> remarkably simple implementation:
>
> def mytee(xs, n):
> last
On Sun, 15 Apr 2018 00:05:58 -0500
Tim Peters wrote:
> Just for fun - no complaint, no suggestion, just sharing a bit of code
> that tickled me.
>
> The docs for `itertools.tee()` contain a Python work-alike, which is
> easy to follow. It gives each derived generator its
Just for fun - no complaint, no suggestion, just sharing a bit of code
that tickled me.
The docs for `itertools.tee()` contain a Python work-alike, which is
easy to follow. It gives each derived generator its own deque, and
when a new value is obtained from the original iterator it pushes that
10 matches
Mail list logo