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__() -- http://mail.python.org/mailman/listinfo/python-l

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

2007-01-16 Thread Dongsheng Ruan
list in Python. "Gary Herron" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Dongsheng Ruan wrote: >> with a cell class like this: >> >> #!/usr/bin/python >> >> import sys >> >> class Cell: >> >> def

How to pass arguments to the function embedded in the timeit.Timer()

2007-01-18 Thread Dongsheng Ruan
Hi Does anybody know how to pass multiple arguments to the function tested in timeit.timer() in python? I googled and found how to pass one argument: x=1 mytime = timeit.Timer( setup="from Createlst import createlst", stmt= "createlst(%s)"%(x) ) But how can I extend it to two or more

What is the dummy statement that do nothing in Python?

2007-01-31 Thread Dongsheng Ruan
I remember that in python there is some kind of dummy statement that just holds space and does nothing. I want it to hold the place after a something like if a>b: do nothing I can't just leave the space blank after if statement because there will be error message. Does anybody know what to ins

Re: What is the dummy statement that do nothing in Python?

2007-01-31 Thread Dongsheng Ruan
Yes, that's just what I want. Thanks! - Original Message - From: Analog Kid To: Dongsheng Ruan Cc: python-list@python.org Sent: Wednesday, January 31, 2007 12:04 PM Subject: Re: What is the dummy statement that do nothing in Python? hey dongsheng: not too sure

need help on a data structure problem

2007-02-01 Thread Dongsheng Ruan
Not quite related with Python. But my Data Structure course is experiemented on python and there is no data structure group, So I have to post here: Write a procedure (in pseudocode!) to increase the number of buckets in a (closed) hash table. Analyze its time and space complexity. -- http:/

Re: confused about resizing array in Python

2007-02-03 Thread Dongsheng Ruan
You mentioned "it doubles in size". Are you saying that a new double sized array is allocated and the contents of the old list is copied there? Then the old list is freed from memory? It seems to be what is called amortized constant. Say the list size is 100, before it is fully used, the append

Re: confused about resizing array in Python

2007-02-03 Thread Dongsheng Ruan
This seems to be clever to use reference for list. Is it unique to Python? How about the traditional programming languages like C, Pascal or C++? "Roel Schroeven" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Dongsheng Ruan schreef: >> "Roe

what is wrong with my python code?

2007-02-07 Thread Dongsheng Ruan
I got feed back saying" list object is not callable". But I can't figure out what is wrong with my code. A=[3,5,4,9,6,7] l=len(A)-1 for i in range(l): print A(i) -- http://mail.python.org/mailman/listinfo/python-list

Why doesn't my heapify work?

2007-02-07 Thread Dongsheng Ruan
I want to turn an Array into a heap, but my code just doesn't work: no change after execution. A=[3,5,4,9,6,7] m=len(A)-1 for i in range(m,1): t=(i-1)/2 if A[i]>A[t]: A[i],A[t]=A[t],A[i] -- http://mail.python.org/mailman/listinfo/python-list