Re: confused about resizing array in Python

2007-02-05 Thread Neil Cerutti
On 2007-02-04, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: How about the traditional programming languages like C, Pascal or C++? For a start they don't have a built in list type. C and Pascal don't even have one in the standard library. C++ has STL vectors and if you, the

Re: confused about resizing array in Python

2007-02-05 Thread Gabriel Genellina
En Sat, 03 Feb 2007 21:34:19 -0300, Dongsheng Ruan [EMAIL PROTECTED] escribió: 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++? Python is written in C - so obviously it can be done in plain

Re: confused about resizing array in Python

2007-02-04 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Dongsheng Ruan wrote: This seems to be clever to use reference for list. Is it unique to Python? No of course not. Java is very similar in only passing references around for objects. And `ArrayList` and `Vector` behave similar to Python lists. How about the

confused about resizing array in Python

2007-02-03 Thread Ruan
My confusion comes from the following piece of code: memo = {1:1, 2:1} def fib_memo(n): global memo if not n in memo: memo[n] = fib_memo(n-1) + fib_memo(n-2) return memo[n] I used to think that the time complexity for this code is O(n) due to its use of memoization. However, I was told

Re: confused about resizing array in Python

2007-02-03 Thread Roel Schroeven
Ruan schreef: My confusion comes from the following piece of code: memo = {1:1, 2:1} def fib_memo(n): global memo if not n in memo: memo[n] = fib_memo(n-1) + fib_memo(n-2) return memo[n] I used to think that the time complexity for this code is O(n) due to its use of memoization.

Re: confused about resizing array in Python

2007-02-03 Thread Ruan
Then how about Python's list? What is done exactly when list.append is executed? For list, is there another larger list initialized and the contents from the old list is copied to it together with the new appended list? Roel Schroeven [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]

Re: confused about resizing array in Python

2007-02-03 Thread John Machin
On Feb 4, 7:41 am, Ruan [EMAIL PROTECTED] wrote: Then how about Python's list? What is done exactly when list.append is executed? For list, is there another larger list initialized and the contents from the old list is copied to it together with the new appended list? Qi ren you tian :-)

Re: confused about resizing array in Python

2007-02-03 Thread Roel Schroeven
Ruan schreef: Roel Schroeven [EMAIL PROTECTED] wrote: Ruan schreef: My confusion comes from the following piece of code: memo = {1:1, 2:1} def fib_memo(n): global memo if not n in memo: memo[n] = fib_memo(n-1) + fib_memo(n-2) return memo[n] I used to think that the time complexity for

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 Roel Schroeven
Dongsheng Ruan schreef: Roel Schroeven [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Ruan schreef: Then how about Python's list? What is done exactly when list.append is executed? For list, is there another larger list initialized and the contents from the old list is copied

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: Roel Schroeven [EMAIL PROTECTED] wrote in