list indices must be integers or slices, not list
时间: 2023-10-12 08:18:39 浏览: 134
quad-indices:创建四边形(两个三角形)的索引
This error occurs when you try to use a list as an index or slice for another list or sequence object, which is not supported in Python.
For example, if you have a list `my_list` and you try to access its elements using another list `index_list`, like this:
```
my_list = [1, 2, 3, 4, 5]
index_list = [1, 2, 3]
result = my_list[index_list]
```
You will get the "list indices must be integers or slices, not list" error because `index_list` is a list and not a valid index or slice for `my_list`.
To fix this error, you need to use integer or slice indices when accessing list elements. For example:
```
my_list = [1, 2, 3, 4, 5]
index_list = [1, 2, 3]
result = [my_list[i] for i in index_list]
```
This will create a new list `result` containing the elements of `my_list` at the indices specified in `index_list`.
阅读全文