2

I'm learning python and wanted to use multidimensional array like we use in c and researched about it and have written the code but stuck at one place and I don't understand why the error is occurring.

My Code:-

a=[]
i=0
for record in tablerows: 
    a.append([])
    rowcells=record.findAll('td')
    for data in rowcells[1:4]:
        a[i].append(data.text)
        i=i+1
        print(a)

Error:

a[i].append(data.text) IndexError: list index out of range.

On second iteration.
Can you please guide me...?
And I'm doing it right or is there a better way of doing it....?

Dennis Soemers
  • 8,090
  • 2
  • 32
  • 55
ronaldo
  • 107
  • 1
  • 2
  • 10

1 Answers1

1

Shift i = i + 1 out of the second loop, like this.

a=[]
i=0
for record in tablerows: 
    a.append([])
    rowcells=record.findAll('td')
    for data in rowcells[1:4]:
        a[i].append(data.text)
        print(a)
    i=i+1
Javier Lim
  • 149
  • 1
  • 14