Retain all entries except for one key python

后端 未结 7 580
情书的邮戳
情书的邮戳 2020-12-10 10:16

I have a python dictionary. Just to give out context, I am trying to write my own simple cross validation unit.

So basically what I want is to get all the values exc

7条回答
  •  Happy的楠姐
    2020-12-10 10:41

    for key, value in your_dict.items():
        if key not in your_blacklisted_set:
            print value
    

    the beauty is that this pseudocode example is valid python code.

    it can also be expressed as a list comprehension:

    resultset = [value for key, value in your_dict.items() if key not in your_blacklisted_set]
    

提交回复
热议问题