且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

合并Python列表中的一些列表项

更新时间:2023-02-05 16:30:18

合并应在什么基础上进行?您的问题相当模糊.另外,我假设a,b,...,f应该是字符串,即'a','b',...,'f'.

On what basis should the merging take place? Your question is rather vague. Also, I assume a, b, ..., f are supposed to be strings, that is, 'a', 'b', ..., 'f'.

>>> x = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> x[3:6] = [''.join(x[3:6])]
>>> x
['a', 'b', 'c', 'def', 'g']

序列类型,尤其是可变序列类型.也许也在字符串方法上.

Check out the documentation on sequence types, specifically on mutable sequence types. And perhaps also on string methods.