[Tutor] Linked List

Shitiz Bansal shitizb at yahoo.com
Sat Mar 5 15:20:40 CET 2005


I could not understand what you exactly mean.

In order to explain wat my problem is, here is an
example code. Its not exactly what I am doing, I am
using multiple threads and a rather complicated code
so  try and understand the sense rather than the code
itself.

>>> myls=range(50)
>>> for i in myls:
	print i
	if i==20:
		myls.insert(5,5)

The point is, the list(both size and elements) is
changing even as it is being operated upon.

This particular case goes into infinite loop at i=20.

Interestingly, I can freely edit the list yet to be
traversed, without any ill effects, which would not
have been possible if a python list was a pure
array(due to immutable length of an array in c).

Shitiz

--- "Jacob S." <keridee at jayco.net> wrote:

> I'm taking a shot in the dark and answering here.
> 
> Have you tried making a copy of the list, iterating
> over the copy, and 
> changing the original based on the copy?
> 
> Jacob
> 
> > Hi,
> > Any body has any idea on how to implement a linked
> > list in python?
> > Ordinary python lists are not quite the same. what
> i
> > need  is a list i can traverse through
> sequentially
> > without bothering about the indices, as another
> > process is continuously editing this list, by
> > inserting and deleting elements even as the list
> is
> > being traversed.
> >
> > Shitiz
> >
> >
> >
> >
> > __________________________________
> > Celebrate Yahoo!'s 10th Birthday!
> > Yahoo! Netrospective: 100 Moments of the Web
> > http://birthday.yahoo.com/netrospective/
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> > 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Tutor mailing list