我正在尝试在 python 中合并两个字符串列表,例如:
['this','is','list one'] ,['and','list two','combined']
成为一个列表。
"+" and "join".
不适合我
原始代码:
for word in passwordslist:
frequencyList+=[word[x:x+N] for x in xrange(len(word)-N+1)]
(试图收集所有 N-gram 的字符串密码列表)
我正在尝试在 python 中合并两个字符串列表,例如:
['this','is','list one'] ,['and','list two','combined']
成为一个列表。
"+" and "join".
不适合我
原始代码:
for word in passwordslist:
frequencyList+=[word[x:x+N] for x in xrange(len(word)-N+1)]
(试图收集所有 N-gram 的字符串密码列表)
初始化列表?
frequencyList = []
for word in passwordslist:
frequencyList += [word[x:x+N] for x in xrange(len(word)-N+1)]
你也可以把它写成一种理解:
frequencyList = [
word[x:x+N]
for word in passwordslist
for x in xrange(len(word)-N+1)
]
>>> 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']