公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.List.splice
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
从起始索引开始,从列表中移除指定数量的元素,并将其他列表的内容插入到该位置。如果 start 为负数,则从列表末尾开始反向计数。
用法 | 返回 |
---|
List.splice(start, count, other) | 列表 |
参数 | 类型 | 详细信息 |
---|
此:list | 列表 | |
start | 整数 | |
count | 整数 | |
other | 列表,默认值:null | |
示例
代码编辑器 (JavaScript)
// An ee.List object.
var list = ee.List([0, 1, 2, 3, 4]);
print('Original list', list);
// If "other" argument is null, elements at positions specified by "start" and
// "count" are deleted. Here, the 3rd element is removed.
print('Remove 1 element', list.splice({start: 2, count: 1, other: null}));
// If "start" is negative, the position is from the end of the list.
print('Remove 2nd from last element', list.splice(-2, 1));
// Deletes 3 elements starting at position 1.
print('Remove multiple sequential elements', list.splice(1, 3));
// Insert elements from the "other" list without deleting existing elements
// by specifying the insert "start" position and setting "count" to 0.
print('Insert new elements', list.splice(2, 0, ['X', 'Y', 'Z']));
// Replace existing elements with those from the "other" list by specifying the
// "start" position to replace and the "count" of proceeding elements. If
// length of "other" list is greater than "count", the remaining "other"
// elements are inserted, they do not replace existing elements.
print('Replace elements', list.splice(2, 3, ['X', 'Y', 'Z']));
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
# An ee.List object.
ee_list = ee.List([0, 1, 2, 3, 4])
print('Original list:', ee_list.getInfo())
# If "other" argument is None, elements at positions specified by "start" and
# "count" are deleted. Here, the 3rd element is removed.
print('Remove 1 element:',
ee_list.splice(start=2, count=1, other=None).getInfo())
# If "start" is negative, the position is from the end of the list.
print('Remove 2nd from last element:', ee_list.splice(-2, 1).getInfo())
# Deletes 3 elements starting at position 1.
print('Remove multiple sequential elements:', ee_list.splice(1, 3).getInfo())
# Insert elements from the "other" list without deleting existing elements
# by specifying the insert "start" position and setting "count" to 0.
print('Insert new elements:', ee_list.splice(2, 0, ['X', 'Y', 'Z']).getInfo())
# Replace existing elements with those from the "other" list by specifying the
# "start" position to replace and the "count" of proceeding elements. If
# length of "other" list is greater than "count", the remaining "other"
# elements are inserted, they do not replace existing elements.
print('Replace elements:', ee_list.splice(2, 3, ['X', 'Y', 'Z']).getInfo())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eList.splice()\u003c/code\u003e modifies a list by removing elements and inserting new ones at a specified position.\u003c/p\u003e\n"],["\u003cp\u003eIt takes \u003ccode\u003estart\u003c/code\u003e, \u003ccode\u003ecount\u003c/code\u003e, and \u003ccode\u003eother\u003c/code\u003e as arguments to control the modification process.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estart\u003c/code\u003e determines the starting position for removal/insertion, while \u003ccode\u003ecount\u003c/code\u003e determines the number of elements to remove.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eother\u003c/code\u003e provides the elements to insert; if \u003ccode\u003eother\u003c/code\u003e is null or None, elements are only removed.\u003c/p\u003e\n"],["\u003cp\u003eA negative \u003ccode\u003estart\u003c/code\u003e value counts backwards from the end of the list for positioning.\u003c/p\u003e\n"]]],[],null,["# ee.List.splice\n\nStarting at the start index, removes count elements from list and insert the contents of other at that location. If start is negative, it counts backwards from the end of the list.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------------|---------|\n| List.splice`(start, count, `*other*`)` | List |\n\n| Argument | Type | Details |\n|--------------|---------------------|---------|\n| this: `list` | List | |\n| `start` | Integer | |\n| `count` | Integer | |\n| `other` | List, default: null | |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// An ee.List object.\nvar list = ee.List([0, 1, 2, 3, 4]);\nprint('Original list', list);\n\n// If \"other\" argument is null, elements at positions specified by \"start\" and\n// \"count\" are deleted. Here, the 3rd element is removed.\nprint('Remove 1 element', list.splice({start: 2, count: 1, other: null}));\n\n// If \"start\" is negative, the position is from the end of the list.\nprint('Remove 2nd from last element', list.splice(-2, 1));\n\n// Deletes 3 elements starting at position 1.\nprint('Remove multiple sequential elements', list.splice(1, 3));\n\n// Insert elements from the \"other\" list without deleting existing elements\n// by specifying the insert \"start\" position and setting \"count\" to 0.\nprint('Insert new elements', list.splice(2, 0, ['X', 'Y', 'Z']));\n\n// Replace existing elements with those from the \"other\" list by specifying the\n// \"start\" position to replace and the \"count\" of proceeding elements. If\n// length of \"other\" list is greater than \"count\", the remaining \"other\"\n// elements are inserted, they do not replace existing elements.\nprint('Replace elements', list.splice(2, 3, ['X', 'Y', 'Z']));\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# An ee.List object.\nee_list = ee.List([0, 1, 2, 3, 4])\nprint('Original list:', ee_list.getInfo())\n\n# If \"other\" argument is None, elements at positions specified by \"start\" and\n# \"count\" are deleted. Here, the 3rd element is removed.\nprint('Remove 1 element:',\n ee_list.splice(start=2, count=1, other=None).getInfo())\n\n# If \"start\" is negative, the position is from the end of the list.\nprint('Remove 2nd from last element:', ee_list.splice(-2, 1).getInfo())\n\n# Deletes 3 elements starting at position 1.\nprint('Remove multiple sequential elements:', ee_list.splice(1, 3).getInfo())\n\n# Insert elements from the \"other\" list without deleting existing elements\n# by specifying the insert \"start\" position and setting \"count\" to 0.\nprint('Insert new elements:', ee_list.splice(2, 0, ['X', 'Y', 'Z']).getInfo())\n\n# Replace existing elements with those from the \"other\" list by specifying the\n# \"start\" position to replace and the \"count\" of proceeding elements. If\n# length of \"other\" list is greater than \"count\", the remaining \"other\"\n# elements are inserted, they do not replace existing elements.\nprint('Replace elements:', ee_list.splice(2, 3, ['X', 'Y', 'Z']).getInfo())\n```"]]