Can double-linked lists be implemented in python?

Dave Kuhlman dkuhlman at rexx.com
Wed Apr 2 12:45:37 EST 2003


Peter Hansen wrote:

> Robin Munn wrote:
>> 
>> sdieselil <sdieselil at yahoo.com> wrote:
>> > Hi
>> >
>> > How can I implement double-linked lists and other complex tree-like
>> > structures in Python?
>> 
>> Do you *need* doubly-linked lists? Is there something that Python's
>> builtin list type can't do for you? Consider whether it's worth taking
>> the time to code up a data structure, with all the attendant edge cases,
>> when you've already got such nice useful builtin types...
> 
> I can think of at least one example where one would *need* doubly-linked
> lists... a homework assignment.  ;-)

But suppose that I *do* implement double linked lists.  I'll have two 
objects that point at each other, in other words circular references.

In older versions of Python, circular references were not garbage collected.  
Is this still true in Python 2.2 and 2.3?  Do I need to use the gc module 
to *enable* garbage collection?  Or, is not *disabling* it good enough?  Do 
I still need to worry about this?  And, suppose you tell me that circular 
references are collected but I don't believe you.  How can I check?

After reading the documentation on the gc module ("3.2 gc --  Garbage 
Collector interface" in the Python Library Reference), I *think* I 
understand this, but am not sure.  Is there a document that explains this?  
I could not find one at www.python.org.  For those of us who want to 
promote Python, it would be nice to have a document that we could point to 
and say, "See. Problem solved. Nothing to worry about."

  - Dave

-- 
Dave Kuhlman
dkuhlman at rexx.com
http://www.rexx.com/~dkuhlman




More information about the Python-list mailing list