[Tutor] working with empty lists

Rance Hall ranceh at gmail.com
Thu Sep 16 06:05:52 CEST 2010


Im working on a little piece of test code to test an idea for a larger script.

Here is what I've got so far:

l = []

for i in range(0,10)
    l.append(i)

for i in range(0,10)
    print('%s. %s' % (i, l[i])


This gives me:

0. 0
1. 1
2. 2 .... etc

which is what I expect, but what I want is to get something like

0. 1
1. 2
2. 3 .....

so that the output is clearly different on either side of the "."

I tried changing the append to l.append(i+1)

which almost worked but the output started with 1. 2  I was curious
what happend to the 0. 1 line

I know this means that I'm not understanding exactly what append actually does.

I know that my ide shows that the list as other functions like insert, etc.

Can someone explain to me whats the best way to add a value to a list
that is not long enough to accept it, without playing with the
indexes, it appears I currently am playing with them.

I know generally that we aren't supposed to care about the indexes but
this is eventually going to be part of a menuing system that displays
the index, so I do have a legit need to care about what is happening
to the list index.


More information about the Tutor mailing list