如何检查列表字典中是否存在某个元素?

时间:2018-07-30 17:24:14

标签: python

例如,如果我有一个字典“ dict”,其中包含3个列表作为值:{1: ['A', 'B', 'C'], 2: ['D'], 3: ['Z']}

如何检查“ D”是否为字典中3个列表中的任何一个?

'C' in dict.values()不起作用,我认为这是因为“ dict”仅包含列表作为值,而不是字母。

1 个答案:

答案 0 :(得分:2)

您可以将字典值展平到一个列表,然后检查Biggest Trade Increase:= VAR Fixed_Impact = [Fixed Impact] VAR EDLP_Impact = [EDLP Impact] VAR Var_Impact = [Var Impact] VAR SP_Impact = [SP Impact] VAR PriceMatch_Impact = [PriceMatch Impact] VAR Incentive_Impact = [Incentives Impact] VAR MAX_Value = MAX( MAX( MAX( Fixed_Impact, EDLP_Impact), MAX( SP_Impact, PriceMatch_Impact )), MAX(Incentive_Impact, Var_Impact)) RETURN SWITCH( TRUE(), Fixed_Impact <> BLANK() && Fixed_Impact = MAX_Value, "Fixed", EDLP_Impact <> BLANK() && EDLP_Impact = MAX_Value, "EDLP", Var_Impact <> BLANK() && Var_Impact = MAX_Value, "Variable", SP_Impact <> BLANK() && SP_Impact = MAX_Value, "Special Promo", PriceMatch_Impact <> BLANK() && PriceMatch_Impact = MAX_Value, "PriceMatch", Incentive_Impact <> BLANK() && Incentive_Impact = MAX_Value, "Incentives" ) 是否在该展平列表中:

C