Answer the question
In order to leave comments, you need to log in
Write a program that swaps any two columns in an array, how to fix it?
Given a two-dimensional array. Write a program that swaps any two columns in
an
array
matrix =
print(matrix)
N = 4
for i in range(N):
c = matrix[i][2]
matrix[i][2] = matrix[i][4]
matrix[i][4] = c
print(matrix)
matrix[i][2] = matrix[i][4]
IndexError: list index out of range
Answer the question
In order to leave comments, you need to log in
You need to include jquery before select2
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
Of course, I'm not strong in python, but arrays are indexed from 0, i.e. if you have 4 elements in the array, then they will be at indexes 0,1,2,3. And in these lines you have 4 indexes that do not exist in this array, which is what the error tells you
IndexError: list index out of range:
for i in range(N):
c = matrix[i][2]
matrix[i][2] = matrix[i][4] // выход за пределы массива
matrix[i][4] = c // выход за пределы массива
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question