[英]How to find a word in a string phrase in a list?
When I do this code it returns false, I wanted it to return True because the "hello" is into "hello word".当我执行此代码时,它返回 false,我希望它返回 True,因为“hello”在“hello word”中。
a = ["hello world", 22]
print("hello" in a)
It' return false, not True.它返回 false,而不是 True。
If i do (not in a list):如果我这样做(不在列表中):
a = "hello world"
print("hello" in a)
It's return True.它返回 True。
Would this do what you need:这会做你需要的:
any(["hello" in str(x) for x in a])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.