我有一个清单, temp1 = ['a','b','c','d','e','f']

我希望将输出作为新列表new_list=['a.b.c.d.e.f']

我试过了

def combine(temp1, lstart, lend):
    global y,z,x
    for w in temp1[lstart:lend-1]: 
        y=w+"."
        z=w
    for w in temp1[lend-1:lend]:
        z=w

for i in edge_names:
    temp1=(i.split('.'))
    print(temp1)
    right = len(temp1) - 2
    combine(temp1, 0, right)

但无法获得理想的结果。请帮忙!

分析解答

您也可以这样做(但还有其他答案中指出的更好的方法)。

s=''  
for i in range(len(temp1)-1):
    s =  s + temp1[i] + '.'
if len(temp1) > 0:
    s =  s + temp1[-1]
newlist = [s]