Indexes of type Error: list must be integers or fragments, not a list

array = some list with three columns and an unlimited number of rows with data inside it.

Volume = array[0][2] 
counter = 0
for i in array: 
    if Volume == array[i][2]: #<------ why is this line a problem? 
        counter += 1
+9
source share
2 answers

This is a classic mistake. iin your case there is already an element from array(i.e. another list) and not an index array(not int), so

if Volume == i[2]:
    counter += 1

Please be sure to check out at least the beginning of the Python lesson , because this is a very simple and fundamental material.

: (volume, Volume). i . row elem .

+11

, , , ( ):

import numpy as np
integerarray = np.array([33,11,22], dtype=int)
integerlist = [33,11,22]
indexArray = [1,2,0]  # or equivalently, an array, e.g. np.argsort(integerlist)
print(integerarray[indexArray]) ## works fine
print(integerlist[indexArray])  ## triggers: TypeError: list indices must be integers or slices, not list

, . , , .

0

All Articles