擅长:python、mysql、java
<p>您在某处有一个numpy数组,而不是标准的Python类型;请参见<a href="https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous">ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</a>中的示例,并解释了numpy数组引发此异常的原因。在</p>
<p>给定一个包含标准字符串值的基本Python列表对象,并且<code>search_string</code>也是一个字符串,那么您的代码<em>就可以工作</em>:</p>
<pre><code>>>> search_string = 'foo'
>>> my_strings = ["Let's foo the bar", 'There is spam in my egg salad', 'You are barred from entering the foodchain!']
>>> [my_str for my_str in my_strings if search_string in my_str]
["Let's foo the bar", 'You are barred from entering the foodchain!']
</code></pre>