New user questions ... be gentle

Bob Schmertz schmertz at wam.umd.edu
Sun Aug 20 16:48:48 EDT 2000


On Sun, 20 Aug 2000, Courageous wrote:

>
>> I use pointers and linked lists a lot in the other languages.  I have
>> seen some references that hint to a way to do this but it isn't very
>> clear.  Any pointers on this would be very helpful. *grins*
>
>You don't use linked lists in Python unless they are going
>to be extraordinarily large collections of objects (10-50,000
>entries, IIRC). If this becomes important to you, I have a
>Deque implementation which is fairly efficient which will do
>in a pinch.
>

Nevertheless, it never hurts to try to implement a linked list just to get
an idea of how references are similar to pointers.  You might never
actually want to use such a linked list in the real world, but if you
needed to create some more complex data structure, you'd still need to
know how to program in a pointer-like fashion.

A way to do it is to use mutable objects, like lists or dictionaries.  
Since the command "x[1] = ["word", None]" essentially sets a pointer to 
the list on the R.H.S., you can use two-element lists as nodes, with the
0th item containing the data.

See http://www.wam.umd.edu/~schmertz/software/llist.py for a short (not
fully-implemented) example.

-- 
Cheers,
Bob Schmertz




More information about the Python-list mailing list