Python 合并字符串


题目:
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)

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM