`{'_type': 'video', 'extraction_tags': '', 'user_id': '2077093354', 'highlight': None, 'user_info': '{"id":2077093354,"avatar_url":"https:\\/\\/krplus-pic.b0.upaiyun.com\\/avatar\\/201806\\/05084648\\/f1ggwy0wqraluwdz","name":"\\u8d22\\u7ea6\\u4f60","nickname":"\\u8d22\\u7ea6\\u4f60"}', 'project_id': '1', 'vtype': 'normal', 'published_at': '2018-11-13T14:31:09+08:00', 'tag_id': '0', '_score': None, 'column_id': '213', 'title': '商业传奇褚时健:有朋友劝我不要干,但人生总要做些贡献', 'cover': 'https://pic.36krcnd.com/201811/12082329/jhu9pf7ggeosdbft!heading', 'template_info': {'template_extra': {'vtype': 'normal'}, 'template_type': 'small_image', 'template_title': '商业传奇褚时健:有朋友劝我不要干,但人生总要做些贡献', 'template_title_isSame': True, 'template_cover': ['https://pic.36krcnd.com/201811/12082329/jhu9pf7ggeosdbft!heading']}, 'web_cover': 'https://pic.36krcnd.com/201811/12082256/sekti37ljzprt2hj', 'column_name': '商业·氪视频', 'id': '24250', 'summary': '褚时健在谈到人生的触底反弹时说,人生哪个没有错,错可以改正,人总要为社会为国家做些贡献。“有朋友劝我算了不要干`了,我说不要再错总是能做到的。”'}
<class 'dict'>
这个字典里面有video 我这样直接判断不行吗?
if 'video' not in (content):
title_list.append(content['template_info']['template_title'])
time_list.append(content['published_at'])
link_list.append("https://36kr.com/p/{}.html".format(content['id']))
我这里content 不用str 总是不能判断,加了str 就可以判断了
这是为啥呢?
因为str中的in 跟字典中的in 的用法不同。
具体的用法,见下面例子
如果你要判断值是否存在,可以使用dict.values()方法,如下