我是Python新手,如果我的问题看起来很愚蠢,请提前道歉。你知道吗
我试图构建一个函数,在另一个列表的字符串中搜索列表的字符串,并返回所有匹配的单词。更具体地说,我试图检查我在两个列表(poa\u corporate\u identifier/poa\u cnpj\u identifier)中编译的某些关键字是否位于下面的文本列表中。你知道吗
出于某种原因,当我知道关键字列表中有更多的项目也在文本列表的某些字符串中时,我会不断接收单个字符串作为输出。你知道吗
有人能帮我找出为什么我的代码没有给出预期的结果(或者建议另一种有效的方法来实现我的目标)?你知道吗
提前谢谢!你知道吗
text = ['power of attorney',
'(b) to attend any partners’ meeting; (c) to represent the grantor
regarding any change or amendment to the articles of association; (c) to
receive service of process on behalf of the grantor in the event of
judicial proceedings arising from applicable corporate laws in brazil; (d)
to represent the grantor before the central bank of brazil; (e) to
represent the grantor before the brazilian federal revenue office; (f) to
deal and solve any issues before the brazilian federal revenue office, and
to sign any document before that agency including, but not limited to, the
basic cnpj entry document',
'in witness whereof, grantor has caused this document to be executed by
its chief executive officer, mr. [?], in the city of [•], on this [•] day
of [•], [•].']
poa_corporate_identifier = ['articles of association', "partners'
meeting", "shareholders meeting", 'corporate laws', 'corporate books',
'board of commerce']
poa_cnpj_identifier = ['brazilian federal revenue office', 'cnpj', 'basic
cnpj entry document']
poa_nature = poa_corporate_identifier + poa_cnpj_identifier
def term_tracker(document, term_variations):
if isinstance(term_variations, list) == True:
for term in term_variations:
if any([str(term) in i for i in document]) == True:
return term
if any([term_variations in i for i in document]) == True:
return term_variations
else:
print('No term located')
您将通过
return term
返回匹配的第一个术语,而是需要将文档列表中匹配的所有术语附加到术语列表中,然后返回该列表此外,您还需要检查term variances是否是下一个case的字符串,最后您不需要最后一个case,而是始终返回terms列表
输出将是
将函数更改为下面的。你知道吗
因为它没有返回列表,所以你只能得到一个值。你知道吗
相关问题 更多 >
编程相关推荐