[Tutor] Linked List

Jeff Shannon jeffshannon at gmail.com
Sun Mar 6 10:42:11 CET 2005

On Sat, 5 Mar 2005 06:20:40 -0800 (PST), Shitiz Bansal
<shitizb at yahoo.com> wrote:

> 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.

My first thought was to say, "Use a queue.Queue."  But it appears that
you need to be able to do more than just add items at the end of the

I suspect that what you need is along the lines of a "priority queue".
 That is, something that works approximately like a queue, but when
you add items to it, you also specify a priority for them.  Then, when
you retrieve an item from the queue, what you get is not necessarily
the first-inserted item, but rather the item with highest priority.

You might want to check the Cookbook to see if there's a priority
queue recipe there.  If not, I suspect that Google can be convinced to
yield something...

Jeff Shannon

More information about the Tutor mailing list