这是我的情景:
a = ["","","","","","","","","",""] #10 elements. Need not always be blank.
b = ["a","b","c","d"]
我想修改a
,使n
的第一个a
元素替换为b
的元素n = b.size()
:
a = ["a","b","c","d","","","","","",""]
那么,是否有像a.replace(b)
这样简单的东西减去截断?
另一种方法是将a.size() - b.size()
个元素追加到b
。
答案 0 :(得分:2)
您可以使用切片:
a[0, 4] = b
或动态长度:
a[0, b.length] = b