[Tutor] List weirdness
Moos Heintzen
iwasroot at gmail.com
Fri Feb 13 09:38:20 CET 2009
Hi,
I was wondering why this happens. I was trying to create a list of lists.
>>> d = [[]]
>>> d[0][0]=1
Traceback (most recent call last):
File "<stdin>", line 1, in ?
IndexError: list assignment index out of range
>>> d
[[]]
What's wrong with that?
However:
>>> d[0].append(1)
>>> d
[[1]]
I guess I can't reference [0] on an empty list. (I come from a C
background.)
More information about the Tutor
mailing list