我正在尝试将多个列表合并到一个列表中
e.g:['of', 'participants:', '25']['participants:', '25', 'we']['25', 'we', 'require']
:“['of', 'participants:', '25'],['participants:', '25', 'we'],['25', 'we', 'require']
”
for wrd in d:
child=child.lower()
child=child.replace(' ','')
dat =child
r = re.compile(dat)
s=str(wrd)
test=[sentence in dat for sentence in s]
if r.search(s) and any(test):
print(s)
答案 0 :(得分:0)
嗯,我不能完全确定你在做什么。使用正则表达式查看代码。也许最好使用字典。如果你必须使用一个列表,你可以通过循环将它合并到一个元组中。如果有帮助,请告诉我。
>>> list_one = ['of', 'participants:', '25']
>>> list_two = ['participants:', '25', 'we']
>>> list_three = ['25', 'we', 'require']
>>> thing = ()
>>> thing += tuple([list_one])
>>> thing += tuple([list_two])
>>> thing += tuple([list_three])
>>> thing
(['of', 'participants:', '25'], ['participants:', '25', 'we'], ['25', 'we', 'require'])
>>> for i in range(len(thing)):
... print thing[i]
...
['of', 'participants:', '25']
['participants:', '25', 'we']
['25', 'we', 'require']