在python中连接列表中的选定元素

dam*_*mon 0 python list

我有一个(python) list of lists如下

biglist=[ ['1','123-456','hello','there'],['2','987-456','program'],['1','123-456','list','of','lists'] ]
Run Code Online (Sandbox Code Playgroud)

我需要以下面的格式得到它

biglist_modified=[ ['1','123-456','hello there'],['2','987-456','program'],['1','123-456','list of lists'] ]
Run Code Online (Sandbox Code Playgroud)

我需要third element onwards在每个内部列表中连接.我试图通过使用list comprehensions,

def modify_biglist(bigl):
    ret =[]
    for alist in bigl:
        alist[2] = ' '.join(alist[2:])
        del alist[3:]
        ret.append(alist)
    return ret
Run Code Online (Sandbox Code Playgroud)

这样做了..但它看起来有点复杂 - 有一个局部变量ret并使用del?有人可以提出更好的建议

Fre*_*Foo 7

[[x[0], x[1], " ".join(x[2:])] for x in biglist]
Run Code Online (Sandbox Code Playgroud)

或者,就地:

for x in biglist:
    x[2:] = [" ".join(x[2:])]
Run Code Online (Sandbox Code Playgroud)


Sve*_*ach 5

要修改列表,可以使用以下代码简化:

for a in big_list:
    a[2:] = [" ".join(a[2:])]
Run Code Online (Sandbox Code Playgroud)