How can I create a linked list in Python?

Paul Rubin http
Wed Jan 17 18:11:09 EST 2007


"sturlamolden" <sturlamolden at yahoo.no> writes:
> Actually, nesting tuples or lists doesn't really duplicate Lisp cons,
> as one can only create a stack-like object with the nesting. Python
> really need a cons type like Lisp. I think it is time to write one, in
> a plain C extension.

But that's what Lisp does too.  As the poet said:

    One thing the average language lacks
    Is programmed use of push-down stacks.
    But LISP provides this feature free:
    A stack - you guessed it - is a tree.
    An empty stack is simply NIL.
    In order, then, the stack to fill
    A CONS will push things on the top;
    To empty it, a CDR will
    Behave exactly like a pop.
    A simple CAR will get you back
    The last thing you pushed on the stack;
    An empty stack's detectable
    By testing with the function NULL.
    Thus even should a LISPer lose
    With PROGs and GOs, RETURNs and DOs,
    He need his mind not overtax
    To implement recursive hacks:
    He'll utilize this clever ruse
    Of using trees as moby stacks.

            (http://www.gotlisp.com/lambda/lambda.txt)

All Python needs is a way of displaying the lists as (a b c) instead
of [a, [b, [c, None]]], and that can be done in pure Python.



More information about the Python-list mailing list