【发布时间】:2020-03-21 13:21:57
【问题描述】:
我有一个包含 10 个名称的列表和一个包含许多短语的列表。我只想选择包含其中一个名称的短语。
ArrayNames = [Mark, Alice, Paul]
ArrayPhrases = ["today is sunny", "Paul likes apples", "The cat is alive"]
在示例中,考虑到包含 Paul 的面孔,考虑到这两个数组,有没有办法只选择第二个短语? 这是我尝试过的:
def foo(x,y):
tmp = []
for phrase in x:
if any(y) in phrase:
tmp.append(phrase)
print(tmp)
x 是短语数组,y 是名称数组。 这是输出:
if any(y) in phrase:
TypeError: coercing to Unicode: need string or buffer, bool found
我非常不确定我使用的有关 any() 构造的语法。有什么建议吗?
【问题讨论】:
标签: python if-statement syntax any