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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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__':
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
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__':
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
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
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
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
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
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.
--
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
25 matches
Mail list logo