Re: Are Python deques linked lists?

2007-12-12 Thread Neil Cerutti
On 2007-12-10, Hrvoje Niksic [EMAIL PROTECTED] wrote: Neil Cerutti [EMAIL PROTECTED] writes: Anyhow, implementing linked lists in Python is not challenging, but they don't work well with Python iterators, which aren't suitable for a linked list's purposes--so you have to give up the happy-joy

Re: Are Python deques linked lists?

2007-12-11 Thread Peter Otten
Duncan Booth wrote: Peter Otten [EMAIL PROTECTED] wrote: However, you will get into trouble if you try to run two simultaneous iterations over the same LinkedList, so there is room for another exercise ;) That was a bit vague; I saw the shared _cursor attribute but didn't dig deeper

Re: Are Python deques linked lists?

2007-12-11 Thread Duncan Booth
Peter Otten [EMAIL PROTECTED] wrote: Only if you try to modify the list from both of them. One deletion is enough to trigger the assertion: Yes, but the assertion isn't intended to be the complete code. Or you just rule that delete(x) must occur immediately after x = next(). My

Re: Are Python deques linked lists?

2007-12-11 Thread Neil Cerutti
On 2007-12-11, Duncan Booth [EMAIL PROTECTED] wrote: There are lots of ways to handle this. You could save a separate pointer for each iterator. In fact I would expect that to handle all the possible variations of inserting and deleting correctly you do need to keep all the pointers somewhere

Re: Are Python deques linked lists?

2007-12-11 Thread Duncan Booth
Neil Cerutti [EMAIL PROTECTED] wrote: If you put an instrumented iterator through, say, reversed or sorted, you'd lose the ability to use it to modify the list I think that is kind of irrelevant. reversed doesn't take an iterator, it requires a sequence and returns an iterator. sorted will

Re: Are Python deques linked lists?

2007-12-11 Thread Neil Cerutti
On 2007-12-11, Duncan Booth [EMAIL PROTECTED] wrote: Neil Cerutti [EMAIL PROTECTED] wrote: If you put an instrumented iterator through, say, reversed or sorted, you'd lose the ability to use it to modify the list I think that is kind of irrelevant. reversed doesn't take an iterator, it

Re: Are Python deques linked lists?

2007-12-11 Thread Hrvoje Niksic
Neil Cerutti [EMAIL PROTECTED] writes: Anyhow, implementing linked lists in Python is not challenging, but they don't work well with Python iterators, which aren't suitable for a linked list's purposes--so you have to give up the happy-joy for loop syntax in favor of Python's frowny-sad while

Re: Are Python deques linked lists?

2007-12-11 Thread Hrvoje Niksic
Duncan Booth [EMAIL PROTECTED] writes: I do have one last question about a doubly-linked list. Would you have to perform any tricks (del statements) to get the garbage collector to collect every node, or will it just work? It should just work. Fortunately that's trivial to verify: class

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
On 2007-12-10, Neil Cerutti [EMAIL PROTECTED] wrote: On 2007-12-09, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. I was wondering if deque() is the class

Re: Are Python deques linked lists?

2007-12-10 Thread Peter Otten
Neil Cerutti wrote: [linked lists] don't work well with Python iterators, which aren't suitable for a linked list's purposes--so you have to give up the happy-joy for loop syntax in favor of Python's frowny-sad while loops. You can always move the while-loop into a generator and use

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
On 2007-12-10, Peter Otten [EMAIL PROTECTED] wrote: Neil Cerutti wrote: [linked lists] don't work well with Python iterators, which aren't suitable for a linked list's purposes--so you have to give up the happy-joy for loop syntax in favor of Python's frowny-sad while loops. You can always

Re: Are Python deques linked lists?

2007-12-10 Thread Zentrader
Instead of linking records together via some key, I first try out a dictionary of lists. The list for each dictionary key would be the same as a list with a single, forward link. If you have relatively few records per key, it works well. -- http://mail.python.org/mailman/listinfo/python-list

Re: Are Python deques linked lists?

2007-12-10 Thread Duncan Booth
Neil Cerutti [EMAIL PROTECTED] wrote: Python's iterators are unsuitable for mutating the linked list while iterating--the only major application of linked lists. Wrapping in a generator won't allow you to use for loop syntax, unless I'm missing something, which has often happened. It is

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
On 2007-12-10, Duncan Booth [EMAIL PROTECTED] wrote: Neil Cerutti [EMAIL PROTECTED] wrote: Python's iterators are unsuitable for mutating the linked list while iterating--the only major application of linked lists. Wrapping in a generator won't allow you to use for loop syntax, unless I'm

Re: Are Python deques linked lists?

2007-12-10 Thread Ant
On Dec 9, 10:54 pm, John Machin [EMAIL PROTECTED] wrote: On Dec 10, 9:43 am, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. It's on the shelf

Re: Are Python deques linked lists?

2007-12-10 Thread Peter Otten
Neil Cerutti wrote: On 2007-12-10, Duncan Booth [EMAIL PROTECTED] wrote: def test(): ll = LinkedList([random.randint(1,1000) for i in range(10)]) for el in ll: if el.value%2==0: ll.delete(el) print [el.value for el in ll] if __name__=='__main__':

Re: Are Python deques linked lists?

2007-12-10 Thread Duncan Booth
Peter Otten [EMAIL PROTECTED] wrote: Neil Cerutti wrote: On 2007-12-10, Duncan Booth [EMAIL PROTECTED] wrote: def test(): ll = LinkedList([random.randint(1,1000) for i in range(10)]) for el in ll: if el.value%2==0: ll.delete(el) print [el.value for el

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
On 2007-12-10, Peter Otten [EMAIL PROTECTED] wrote: Neil Cerutti wrote: def test(): ll = LinkedList([random.randint(1,1000) for i in range(10)]) for el in ll: if el.value%2==0: ll.delete(el) print [el.value for el in ll] if __name__=='__main__':

Re: Are Python deques linked lists?

2007-12-10 Thread Neil Cerutti
On 2007-12-10, Neil Cerutti [EMAIL PROTECTED] wrote: On 2007-12-10, Peter Otten [EMAIL PROTECTED] wrote: Neil Cerutti wrote: def test(): ll = LinkedList([random.randint(1,1000) for i in range(10)]) for el in ll: if el.value%2==0: ll.delete(el) print

Re: Are Python deques linked lists?

2007-12-10 Thread Raymond Hettinger
I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. I was wondering if deque() is the class to use or if there's something else. Is there? The deque is implemented as a list of arrays. See 5.12.1 Recipes for the trick

Re: Are Python deques linked lists?

2007-12-10 Thread Arnaud Delobelle
On Dec 9, 10:54 pm, John Machin [EMAIL PROTECTED] wrote: On Dec 10, 9:43 am, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. It's on the shelf

Re: Are Python deques linked lists?

2007-12-10 Thread John Machin
On Dec 10, 7:37 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote: On Dec 9, 10:54 pm, John Machin [EMAIL PROTECTED] wrote: On Dec 10, 9:43 am, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm looking for a linked list implementation. Something iterable with

Are Python deques linked lists?

2007-12-09 Thread Just Another Victim of the Ambient Morality
I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. I was wondering if deque() is the class to use or if there's something else. Is there? Thank you... -- http://mail.python.org/mailman/listinfo/python-list

Re: Are Python deques linked lists?

2007-12-09 Thread John Machin
On Dec 10, 9:43 am, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. It's on the shelf between the jar of phlogiston and the perpetual motion machine. --

Re: Are Python deques linked lists?

2007-12-09 Thread Neil Cerutti
On 2007-12-09, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm looking for a linked list implementation. Something iterable with constant time insertion anywhere in the list. I was wondering if deque() is the class to use or if there's something else. Is there? The