Filter dict to contain only certain keys?

后端 未结 15 1154
耶瑟儿~
耶瑟儿~ 2020-11-22 10:52

I\'ve got a dict that has a whole bunch of entries. I\'m only interested in a select few of them. Is there an easy way to prune all the other ones out?

15条回答
  •  借酒劲吻你
    2020-11-22 11:30

    You can do that with project function from my funcy library:

    from funcy import project
    small_dict = project(big_dict, keys)
    

    Also take a look at select_keys.

提交回复
热议问题