小编Aut*_*isk的帖子

在Python中为列表中的值范围添加值的最有效方法?

将整数添加到列表的一部分的最有效方法是什么?

示例:

input : [1,5,3,7,4,3]

range of list to modify is 2,4

add 3 to range

output : [1,5,6,10,7,3]
Run Code Online (Sandbox Code Playgroud)

说明:

首先使用索引2和4获取子列表.然后将3添加到该索引中的值.然后返回包含修改范围的列表.

我尝试使用循环,但速度不够快.需要更快的方法.

python performance

-2
推荐指数
1
解决办法
98
查看次数

标签 统计

performance ×1

python ×1