Question

So I have a matrix like:

1 2 3 4
0 3 4 1
7 3 4 5

And I want to select a row,then use this row to do stuff on it such as sorting it with some algorithms;I made this so far:

def row_management(matrix):

   theline = input('wich line?') #enter row number
   thelist = [matrix[theline]]  #go take the right row of the matrix
   menu_thelist(thelist)  #supossed to use the row and take it to the list management menu

However, when I run this, it always return an error "[matrix[theline]] TypeError: list indices must be integers, not str" and I don't get it.

Was it helpful?

Solution 2

Needed to convert to int

theline = int(input('wich line?'))

And also

thelist = matrix[theline]

the have [1,2,3] and not [[1,2,3]](wich cause further problem)

OTHER TIPS

The input call returns a str type, so it can not be used directly as index to the list inmatrix[theline], which is also what the error message says. Instead do:

matrix[int(theline)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top