2024-06-28 19:25:31 发布
网友
从{cd2>中提取。我该怎么做?我被难住了,因为我不知道如何找出食物中的哪一项是在字符串中找到的。在
foods = ["bagels", "oranges", "bananas"] thought1 = "I want some bananas-10" thought2 = "I want some 10-bananas" if any(food in thought1 for food in foods): # extractedfood = ???
我将使用以下列表协作方法:
text = thought1 + " " + thought2 # To handle both strings result = [a for a in text.split() for b in foods if b in a] print result
输出:
我将使用以下列表协作方法:
输出:
^{pr2}$相关问题 更多 >
编程相关推荐