python如何合并字符串列表

2024-10-05 10:04:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在python中合并两个字符串列表,比如:

['this','is','list one'] ,['and','list two','combined']

成为一张单子。在

^{pr2}$

不适合我

原代码:

 for word in passwordslist:
    frequencyList+=[word[x:x+N] for x in xrange(len(word)-N+1)]

(尝试收集字符串passwordlist的所有N-gram)


Tags: and字符串in列表foristhisone
2条回答

初始化列表?在

frequencyList = []
for word in passwordslist:
    frequencyList += [word[x:x+N] for x in xrange(len(word)-N+1)]

你也可以将此作为一种理解:

^{pr2}$
>>> first_list = ['this', 'is', 'list one']
>>> second_list = ['and', 'list two', 'combined']
>>> first_list.extend(second_list)
>>> print first_list
['this', 'is', 'list one', 'and', 'list two', 'combined']

相关问题 更多 >

    热门问题