【发布时间】:2017-04-13 03:52:39
【问题描述】:
所以我有一个关键字数组,例如
keyword = ['Bob','hello','boot']
我解析了 json 并抓取了名为 title 的字符串值并输入到 name。
标题包含诸如“Bob hey, hello boot”之类的字符串
我正在尝试使程序仅在 Title/name 包含关键字数组列表中的所有单词时才返回 true。
目前,我有这个代码
keyword = ['Bob','hello','boot']
name=str(item[u'title'].encode('ascii','ignore')) #grab Title and input into name
found_a_string = True
for word in keyword:
if not word in name.lower():
found_a_string = False
if found_a_string:
ID=str(item[u'id'])
print name, ID, 'found' #would output full title and then assoicated ID from json.
但只要关键字中的一个单词匹配,代码就会返回 true。
任何帮助将不胜感激。
谢谢
【问题讨论】:
标签: json python-2.7