简体   繁体   English

Python清单'in'陈述式无法正常运作

[英]Python list 'in' statement doesn't work correctly

I tried to used 'in' function to check some value available in a list or not. 我试图使用“输入”功能来检查列表中是否有可用值。 But it does not work correctly. 但是它不能正常工作。

from nltk.tokenize import word_tokenize

x ='what are bad'
a= word_tokenize(x)[0]
qestion = ['what,why,how,are,am,should']

if a in qestion:
 print 'question'
else:
 print 'not a question'

I couldn't find the reason for that. 我找不到原因。 Can any one help me to solve this. 谁能帮我解决这个问题。

The following certainly is a list, but I don't think it's the list that you were looking for. 以下内容肯定是一个列表,但我认为这不是您要查找的列表。

 qestion = ['what,why,how,are,am,should']

i think what you wanted was 我想你想要的是

question = 'what,why,how,are,am,should'.split(',')

which produces 产生

['what', 'why', 'how', 'are', 'am', 'should']

Which is more likely to full fill your IF x in y condition. 这更有可能在y条件下完全填充您的IF x。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM