Dynamic or not?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Dec 13 10:29:17 EST 2007


rishiyoor at gmail.com a écrit :
> On Dec 12, 11:33 pm, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
(snip)
> 
> When you say python automatically allocates memory, what would you do
> if you don't know the size of the list

thelist = []
thelist.append('Ever')
thelist.append('bothered')
thelist.append('reading')
thelist.append('the')
thelist.append('fine')
thelist.append('manual')
thelist.append('?')

print thelist

> of, say for example, the
> nearest pairs between the two groups. I would probably iterate over
> all the pairs and create a new list. I did a similar operation in
> another program, but I had to initialize the list (statically) with x
> = [0]*50 before I could use it in the for loop.

You'd be better learning how to properly use lists and iterations in 
Python... While you're at it, add list comprehensions, 
iterators/generators and itertools to the list (pun intented).

HTH



More information about the Python-list mailing list