标签:range strong ace 合并字符串 python 字符 lse col append
题目:
a1=[‘A1‘,‘A2‘,‘B1‘,‘B2‘,‘C1‘,‘C2‘,‘C3‘,‘D1‘,‘D2‘]
a2=[‘A‘,‘B‘,‘C‘,‘D‘]
a1合并a2后得到这样的列表[‘A1‘, ‘A2‘, ‘A‘, ‘B1‘, ‘B2‘, ‘B‘, ‘C1‘, ‘C2‘, ‘C3‘, ‘C‘, ‘D1‘, ‘D2‘, ‘D‘]
废话不多说,直接上代码
a1=[‘A1‘,‘A2‘,‘B1‘,‘B2‘,‘C1‘,‘C2‘,‘C3‘,‘D1‘,‘D2‘]
a2=[‘A‘,‘B‘,‘C‘,‘D‘]
start_place=0
for item in a2:
for i in range(start_place,len(a1)):
if i==len(a1)-1:
a1.append(item)
print("insert charater %s"%item)
start_place=i+1
else:
str=a1[i]
if str.startswith(item) is False:
a1.insert(i,item)
print("insert charater %s"%item)
start_place = i + 1
break
print(a1)
标签:range strong ace 合并字符串 python 字符 lse col append
原文地址:https://www.cnblogs.com/sunnyxhd/p/11196102.html