>>> 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!']
作为错误消息表示:-在
这意味着您的代码包含numpy数组,那么您需要如下所示进行比较:-
^{pr2}$有关详细信息,请参阅this
您在某处有一个numpy数组,而不是标准的Python类型;请参见ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()中的示例,并解释了numpy数组引发此异常的原因。在
给定一个包含标准字符串值的基本Python列表对象,并且
search_string
也是一个字符串,那么您的代码就可以工作:相关问题 更多 >
编程相关推荐