Problem with list assignment
OKB (not okblacke)
BrenBarn at aol.com
Thu Nov 21 11:31:35 EST 2002
Jesse Lawrence wrote:
> i = 0;
> for r in row:
> header[i] = r[0]
> i = i + 1
> return header
>
> Now, when I just do a print r[0] in the for loop, I'm
> getting exactly what I want, it's just that when I try
> to assign it to header, that I get a "list assignment
> index out of range" error.
>
> Am I overlooking something?
It's not legal to assign to an element that doesn't already exist
in the list. Your list has no elements, so it's not legal to assign to
any index. What you want is:
for r in row:
header.append(r[0])
--
--OKB (not okblacke)
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
More information about the Python-list
mailing list