[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Greg Ewing
On 30/04/20 3:32 am, Christopher Barker wrote: I've wondered about Linked Lists for a while, but while there are many versions on PyPi, I can't find one that seems to be mature and maintained. Which seems to indicate that there isn't much demand for them. I think this is probably because a lin

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Greg Ewing
On 29/04/20 11:32 pm, Steven D'Aprano wrote: My reasoning was that *eventually* for a big enough list, the cost of making the copy would outweigh the cost of moving the items. I don't know if my reasoning was valid or not, I think it's not. They're both O(n) in the length of the list, so at mos

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Raymond Hettinger
> On Apr 29, 2020, at 12:02 PM, Christopher Barker wrote: > > On Apr 29, 2020, at 08:33, Christopher Barker wrote: > > I've wondered about Linked Lists for a while, but while there are many > > versions on PyPi, I can't find one that seems to be mature and maintained. > > Which seems to indic

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Rhodri James
On 29/04/2020 20:54, Andrew Barnert via Python-ideas wrote: On Apr 29, 2020, at 12:03, Christopher Barker wrote: Isn't much demand for a*generic* linked list. It would probably be a good recipe though -- so users could have a starting point for their custom version. I think what would be real

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Chris Angelico
On Thu, Apr 30, 2020 at 5:56 AM Andrew Barnert via Python-ideas wrote: > > On Apr 29, 2020, at 12:03, Christopher Barker wrote: > > > > > > Isn't much demand for a *generic* linked list. It would probably be a good > > recipe though -- so users could have a starting point for their custom > > v

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Andrew Barnert via Python-ideas
On Apr 29, 2020, at 12:03, Christopher Barker wrote: > > > Isn't much demand for a *generic* linked list. It would probably be a good > recipe though -- so users could have a starting point for their custom > version. I think what would be really handy would be a HOWTO on linked lists that sh

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Christopher Barker
Thanks for all the details -- it really makes the point I was trying to make. On Apr 29, 2020, at 08:33, Christopher Barker wrote: > > I've wondered about Linked Lists for a while, but while there are many > versions on PyPi, I can't find one that seems to be mature and maintained. > Which seems

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Andrew Barnert via Python-ideas
On Apr 29, 2020, at 08:33, Christopher Barker wrote: > > I've wondered about Linked Lists for a while, but while there are many > versions on PyPi, I can't find one that seems to be mature and maintained. > Which seems to indicate that there isn't much demand for them. I think there’s lots of

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Serhiy Storchaka
29.04.20 17:56, Ram Rachum пише: Thanks everybody for your answers, and especially Ricky for finding this note. Please not that the optimization mentioned in the comment still keeps the linear complexity for these operations. It just reduces the constant multiplier. _

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Christopher Barker
On Wed, Apr 29, 2020 at 8:02 AM Ram Rachum wrote: > Thanks everybody for your answers, and especially Ricky for finding this > note. > which seems to indicate that if one were to implement this code more efficiently, it would be considered for inclusion. I will note that for the most part, the

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Ram Rachum
Thanks everybody for your answers, and especially Ricky for finding this note. On Wed, Apr 29, 2020 at 2:20 PM Ricky Teachey wrote: > I was playing around with deque today, and there were a couple of >> operations I wanted to do, that can't really be done efficiently with deque >> because of its

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Barry Scott
> On 29 Apr 2020, at 12:36, remi.lape...@henki.fr wrote: > > Also, removing an element from a doubly-linked list is not a O(1) operation, > it's O(n). It's O(1) once you have a pointer to the element but you have to > iterate over the list to get it and that would take O(n) operations, so > m

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Steven D'Aprano
On Wed, Apr 29, 2020 at 01:42:05PM +0300, Ram Rachum wrote: > I was iterating through items of a deque, and in some cases I wanted to > delete an item that I've found. Deleting items from a container while iterating through it is an anti-pattern, easy to get wrong, prone to bugs, and in a high-l

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread remi . lapeyre
A deque is a data structure that exists outside of Python and the only guarantee is that adding an element at the top or the front is O(1). Giving more guarantee would force trade-offs and impose them to other implementations. If you want fast deletion, you should use another data structure. Al

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Paul Sokolovsky
Hello, On Wed, 29 Apr 2020 13:58:15 +0300 Ram Rachum wrote: > On Wed, Apr 29, 2020 at 1:54 PM Paul Sokolovsky > wrote: > > > If you want a different data structure, [...] implement such a > > data structure > > > > And if I wanted an answer like "it's the way that it is because it's > the w

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Ricky Teachey
> > I was playing around with deque today, and there were a couple of > operations I wanted to do, that can't really be done efficiently with deque > because of its implementation. > > ... > > What do you think about adding [O(1) insert and remove] this to `deque`? > _collectionsmodule.c has this

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Chris Angelico
On Wed, Apr 29, 2020 at 9:15 PM Chris Angelico wrote: > I'm not seeing any evidence that this is a doubly-linked list. It > might happen to be implemented using one in current versions of > CPython, but that's not mandated anywhere. (And it's not a pure DLL - it's a DLL of blocks of 64 elements a

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Chris Angelico
On Wed, Apr 29, 2020 at 9:01 PM Ram Rachum wrote: > Is there a strategic decision to limit deque to certain operations of > doubly-linked lists and not others? That would make sense. Is that decision > written somewhere with the rationale behind it? That would be interesting to > read. > """De

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Ram Rachum
On Wed, Apr 29, 2020 at 1:54 PM Paul Sokolovsky wrote: > If you want a different data structure, [...] implement such a > data structure > And if I wanted an answer like "it's the way that it is because it's the way that it is" I wouldn't be posting on python-ideas. Is there a strategic decisio

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Paul Sokolovsky
Hello, On Wed, 29 Apr 2020 13:42:05 +0300 Ram Rachum wrote: > I was playing around with deque today, and there were a couple of > operations I wanted to do, that can't really be done efficiently with > deque because of its implementation. > > I was iterating through items of a deque, and in som