【发布时间】:2013-09-22 15:30:16
【问题描述】:
有没有更好的写法:
if "msg" in response_dic or "save_act_errors" in response_dic or "add_act_errors" in response_dic or "modif_act_errors" in response_dic or "update_act_errors" in response_dic:
#do stuff
response_dic 是字典,我正在检查键。
其实有2个问题:
1/ 如何测试字典中的多个键?
2/如何检查部分键(在我的情况下以“_act_errors”结尾)?
【问题讨论】:
-
你是对的,这是一个类似的问题,但在我的情况下,我必须使用任何而不是全部。
标签: python dictionary key