0

I have a multidimensional array with this format:

['201800053193', 'Jane Doe', 'PAUL', None, '1', None, '0', '2', 'N', 83]

There are about 4500 arrays like this inside of another array.

Im looping through it with this:

for ent in entity_array:
    print(ent[9])

But Im getting an error at the end:

in entities
    print(ent[9])
IndexError: list index out of range

Element ent[9] does exist for each sub-array. What could be causing this error?

Looping through this does not give an error:

for ent in entity_array:
    print(ent)
user9794893
  • 133
  • 3
  • 11
  • 3
    Add `print(ent)` just before `print(ent[9])` and you'll find the culprit. – user4815162342 May 29 '18 at 14:37
  • 1
    One (at least) of the (big array) items, has less than 10 elements. Try `print(len(ent))` before `ent[9]`, and also you could use `enumerate` to get the faulty list index in the big 2D array. – CristiFati May 29 '18 at 14:38
  • Use try catch to see which part of the array is causing this issue. More details about catching IndexError is here https://stackoverflow.com/questions/39604377/how-to-catch-an-index-error – nerding_it May 29 '18 at 14:43

1 Answers1

0

I think it suggests that at least one of the subarray has the length less than or equal 9.

you can try the following code to check the lengths first

for ent in entity_array:
    print(len(ent))