Retain all entries except for one key python

后端 未结 7 582
情书的邮戳
情书的邮戳 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条回答
  • 2020-12-10 10:46

    How about something along the following lines:

    In [7]: d = dict((i,i+100) for i in xrange(10))
    
    In [8]: d
    Out[8]: 
    {0: 100,
     1: 101,
     2: 102,
     3: 103,
     4: 104,
     5: 105,
     6: 106,
     7: 107,
     8: 108,
     9: 109}
    
    In [9]: exc = set((2, 5))
    
    In [10]: for k, v in d.items():
       ....:     if k not in exc:
       ....:         print v
       ....:         
       ....:         
    100
    101
    103
    104
    106
    107
    108
    109
    
    0 讨论(0)
提交回复
热议问题