def conc():
l1=l
print(l1[-1])
for i in range(len(l1)-1):
if l1[i] not in l1[i+1]:
s=l1[i]+l1[i+1]
print(s)
if l1[i] not in l1[-1]:
s1=l1[i]+l1[-1]
print(s1)
l=ast.literal_eval(input())
conc()
给定
l=["abc","yyy","def","csv"]
结果应该是
abcdef,defabc,defcsv,csvdef
yyy
没有添加,因为它有重复的字符串
如何实现?
答案 0 :(得分:0)
使用嵌套循环遍历所有单词对(您也可以使用 itertools.product()
)。然后检查单词之间是否有任何共同的字符。
for word1 in l:
for word2 in l:
if not any(c in word1 for c in word 2):
print(word1+word2)