[portland] List Indexing Confusion

Ethan Furman ethan at stoneleaf.us
Fri Aug 12 00:30:47 CEST 2011


Rich Shepard wrote:
> for row in indata:
>   outdata.writerow([loc, row[i][j], parmlist[i], row[i][j+1]])

You're indexing into a string.

row = [
         '1993-11-22', '0.008', '0.014',
         '0.021', '7.560', '2.060',
         '39.3', 293.0
         ]

row[i] = '1993-11-221'  # when i == 0
row[i][j] = '1'         # when i == j == 0


You should be able to do most things in Python without resorting to 
manual indexing:

for row in indata:
     date = row[0]
     for chemical, amount in zip(parmlist, row[1:]):
         outdata.writerow([date, chemical, amount])


~Ethan~


More information about the Portland mailing list