将整数添加到列表的一部分的最有效方法是什么?
示例:
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]
说明:
首先使用索引2和4获取子列表.然后将3添加到该索引中的值.然后返回包含修改范围的列表.
我尝试使用循环,但速度不够快.需要更快的方法.
python performance
performance ×1
python ×1