Re: How can I create a linked list in Python?

2007-01-19 Thread Hendrik van Rooyen
Jorgen Grahn [EMAIL PROTECTED] wrote: FWIW, I oppose the idea (paraphrased from further up the thread) that linked lists and other data structures are obsolete and dying concepts, obsoleted by Python and other modern languages. 99% of the time. a Python list is the right tool for the job,

Re: How can I create a linked list in Python?

2007-01-18 Thread Jorgen Grahn
On Wed, 17 Jan 2007 10:11:40 +0100, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: In [EMAIL PROTECTED], bearophileHUGS wrote: In CPython they are dynamic arrays, they aren't lists. Try adding elements at the beginning of a list compared to adding elements at the beginning or in the

Re: How can I create a linked list in Python?

2007-01-18 Thread sturlamolden
Paul Rubin wrote: But that's what Lisp does too. Ok, I may have to reread Paul Graham's book on ANSI Common Lisp then. -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I create a linked list in Python?

2007-01-18 Thread Neil Cerutti
On 2007-01-18, sturlamolden [EMAIL PROTECTED] wrote: Paul Rubin wrote: But that's what Lisp does too. Ok, I may have to reread Paul Graham's book on ANSI Common Lisp then. Here's something silly I whipped up to play with. r Lisp style singly-linked lists called llist. def consp(o):

Re: How can I create a linked list in Python?

2007-01-17 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], bearophileHUGS wrote: In CPython they are dynamic arrays, they aren't lists. Try adding elements at the beginning of a list compared to adding elements at the beginning or in the middle of a python list and you will see the efficiency differences. Python has a list type

Re: How can I create a linked list in Python?

2007-01-17 Thread bearophileHUGS
Marc 'BlackJack' Rintsch: Python has a list type without the s, it's a real list. Don't confuse the *ADT list* with *linked lists* which are just one implementation of the ADT list. Right, I was mostly talking about (single/double) linked lists :-) Bye, bearophile --

Re: How can I create a linked list in Python?

2007-01-17 Thread Bruno Desthuilliers
sturlamolden a écrit : Bruno Desthuilliers wrote: Implementing linked lists in Python is not a great deal - it just doesn't make much sens. It does make sence, Oh Yec ?-) sorry... as there are memory constraints related to it. Python lists are arrays under the hood. This is

Re: How can I create a linked list in Python?

2007-01-17 Thread sturlamolden
Bruno Desthuilliers wrote: Have you considered using tuples ? If you go the FP way, why not use an immutable type ? Well, good question. Tuples are immutable, which means they are immutable. So you cannot use a cursor to change an element inside the list. So instead of changing the original

Re: How can I create a linked list in Python?

2007-01-17 Thread Paul Rubin
sturlamolden [EMAIL PROTECTED] 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

How can I create a linked list in Python?

2007-01-16 Thread Dongsheng Ruan
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data self.next = next def __str__( self ): return str( self.data ) def echo( self ): print self.__str__() --

Re: How can I create a linked list in Python?

2007-01-16 Thread Gary Herron
Dongsheng Ruan wrote: with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data self.next = next def __str__( self ): return str( self.data ) def echo( self ): print self.__str__() If you really

Re: How can I create a linked list in Python?

2007-01-16 Thread azrael
How can I implement a linked list like the implementations in c with struct-s and arrays (or pointers). to simbolize the working principe Gary Herron je napisao/la: Dongsheng Ruan wrote: with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__(

Re: How can I create a linked list in Python?

2007-01-16 Thread Dongsheng Ruan
Thanks for your kindly help. I am new CS student taking datat structure and algorithms with AHO's book with the same title. The book is done in Pascal, which might be an outdated language. However, my instructor probably wants us to understand the list ADT better by not using the built in list

Re: How can I create a linked list in Python?

2007-01-16 Thread bearophileHUGS
Gary Herron: If you really want a list (as Python defines a list - with all the methods) then you should use Python's lists. They are quite efficient and convenient: In CPython they are dynamic arrays, they aren't lists. Try adding elements at the beginning of a list compared to adding

Re: How can I create a linked list in Python?

2007-01-16 Thread ray223
Dongsheng Ruan wrote: with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data self.next = next def __str__( self ): return str( self.data ) def echo( self ): print self.__str__() Hi, The How to

Re: How can I create a linked list in Python?

2007-01-16 Thread Bruno Desthuilliers
Dongsheng Ruan a écrit : Thanks for your kindly help. I am new CS student taking datat structure and algorithms with AHO's book with the same title. The book is done in Pascal, which might be an outdated language. Yes, somehow - but note, that linked lists are the central data structure

Re: How can I create a linked list in Python?

2007-01-16 Thread Gabriel Genellina
At Tuesday 16/1/2007 17:07, Dongsheng Ruan wrote: Thanks for your kindly help. I am new CS student taking datat structure and algorithms with AHO's book with the same title. The book is done in Pascal, which might be an outdated language. However, my instructor probably wants us to understand

Re: How can I create a linked list in Python?

2007-01-16 Thread kernel1983
Every language has its own way to do the business! Python has a more abstract data type as the common tools. Just do things in pythonic way! On 1月17日, 上午9时55分, Gabriel Genellina [EMAIL PROTECTED] wrote: At Tuesday 16/1/2007 17:07, Dongsheng Ruan wrote: Thanks for your kindly help. I am new CS

Re: How can I create a linked list in Python?

2007-01-16 Thread sturlamolden
Bruno Desthuilliers wrote: Implementing linked lists in Python is not a great deal - it just doesn't make much sens. It does make sence, as there are memory constraints related to it. Python lists are arrays under the hood. This is deliberately. Dynamic arrays grows faster than lists for the