list.insert(i, x)
Insert an item at a given position. The first
argument is the index of the element before which to insert, so
a.insert(0, x) inserts at the front of the list, and a.insert(len(a),
x) is equivalent to a.append(x).
def addmark(lst):
add = 0 # needed cause after every insertion of '!' the position where you want to add the next '!' changes
for i in range (1,len(lst)+1): # (start: adding after ls[0], finish: adding after the last element)
lst.insert(i+add, '!')
add += 1
return lst
使用插入:
引用:docs.python.org/2/tutorial/datastructures
代码:
使用itertools替代公认答案的方法:
相关问题 更多 >
编程相关推荐