row[i] = col[j] = TrueIndexError: list assignment index out of range

简介: row[i] = col[j] = TrueIndexError: list assignment index out of range

Traceback (most recent call last):
 File "C:/Users/PycharmProjects/pySpider/字典/矩阵置零.py", line 26, in <module>
   row[i] = col[j] = True
IndexError: list assignment index out of range

你遇到的错误,“IndexError: list assignment index out of range(索引错误:列表分配索引超出范围)”,表示你正试图为列表中超出实际大小的索引赋值。

在你的具体代码片段中,似乎你正试图在列表rowcol的索引ij处赋值。然而,很可能这些索引超出了列表的实际长度,导致了 IndexError。

要解决此问题,你需要确保索引ij在列表rowcol的有效范围内。以下是一些你可以检查的事项:

  1. 列表初始化: 确保在尝试为特定索引赋值之前,已使用适当的大小初始化了rowcol列表。

例如,使用零进行初始化


row = [0] * some_size
col = [0] * some_size
  1. 索引范围检查: 在为row[i]col[j]赋值之前,请确保ij在列表的有效范围内。你可以添加条件检查来确保这一点。
if 0 <= i < len(row) and 0 <= j < len(col):
    row[i] = col[j] = True
else:
    print("Invalid indices: i =", i, "j =", j)
相关文章
成功解决A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,co
成功解决A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,co
|
10月前
|
存储 安全 关系型数据库
Column length too big for column ‘remark‘ (max=65535)解决办法
Column length too big for column ‘remark‘ (max=65535)解决办法
135 0
|
索引
LeetCode 303. Range Sum Query - Immutable
给定一个整数数组 nums,求出数组从索引 i 到 j (i ≤ j) 范围内元素的总和,包含 i, j 两点。
66 0
LeetCode 303. Range Sum Query - Immutable
|
Python
You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.conca
You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.conca
618 0
|
索引 Python
成功解决ValueError: column index (256) not an int in range(256)
成功解决ValueError: column index (256) not an int in range(256)
成功解决ValueError: column index (256) not an int in range(256)
|
Web App开发 Java 关系型数据库
Data truncation: Data too long for column &#39;xxx&#39; at row 1
Data truncation: Data too long for column 'xxx' at row 1 完整的错误内容可能是下面这样的: p.p1 {margin: 0.0px 0.0px 0.
2077 0
|
Web App开发 关系型数据库 Java
Data truncation: Data too long for column 'xxx' at row 1
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/78870542 ...
2060 0
|
C++ 关系型数据库 Oracle

热门文章

最新文章