How to get the row of a given Python array index

1

I need through the index of an array "column" to access its entire row in order to be able to change the indexes of this row. The part of collecting the indexes I got, but I do not know how to access through this chosen index view the line completely.

  

list1 = [1, 6, 4, 4, 5]

     

list2 = [2, 2, 3, 4, 6]

     

list3 = [3, 9, 8, 7, 3]

     

list4 = [4, 7, 3, 8, 0]

     

array = [list1] + [list2] + [list3] + [list4]

     

column = [line [0] for line in array]

     

print (column)

Then through the index [0] [1,2,3,4], if I choose 2 [3] I need to return the values [9, 8, 7, 3] so that I can change some number, 5 for example. I hope you've been able to explain.

    
asked by anonymous 12.10.2015 / 17:59

2 answers

2

In the example, I reported the position of the line as fixed, and then I reported the starting position of the column to the end position:

lista1 = [1, 6, 4, 4, 5]

lista2 = [2, 2, 3, 4, 6]

lista3 = [3, 9, 8, 7, 3]

lista4 = [4, 7, 3, 8, 0]

matriz = [lista1] + [lista2] + [lista3] + [lista4]

colunas = matriz[2][1:5]

print(colunas)  

So you can only get the values of the columns that you want, just go by changing the positions of the rows and columns to get different values.

I hope I have helped you.

More about arrays here .

    
12.10.2015 / 19:26
0

I have another question, taking advantage of what is in the same file.

When the user is going to choose a number, for example column 2, internally python will work in column 3, I made a test with the code that I modified, causing the user to ask for the column.

  

list1 = [1, 2, 3, 4, 5]

     

list2 = [2, 2, 3, 4, 6]

     

list3 = [3, 9, 8, 7, 3]

     

list4 = [4, 7, 3, 8, 0]

     

array = [list1] + [list2] + [list3] + [list4]

     

number = int (input ("enter the number:"))

     

column = [line [number] for line in array]

     

columns = array [number] [0: 5]

     

columns [1] = 9

     

print (columns)

I tested the solution I had already found.

  

list1 = [1, 2, 3, 4, 5]

     

list2 = [2, 2, 3, 4, 6]

     

list3 = [3, 9, 8, 7, 3]

     

list4 = [4, 7, 3, 8, 0]

     

array = [list1] + [list2] + [list3] + [list4]

     

column = [line [0] -1 for line in array] # -1 type 2 and edit number 2 of column 1

     

print (column [3])

But this way of inserting -1 in the for did not work in the main code. What's missing to work like this second code?

    
12.10.2015 / 23:39