python从属性dicts列表中删除一个键元组

时间:2018-03-29 15:26:00

标签: python-3.x list dictionary

我正在尝试从名为AttributeDictionary的{​​{1}}列表中删除一个键元组

att_dict_list

dict_list = [dict(att_dict.pop(k, None) for k in ('a', 'b', 'e')) for att_dict in att_dict_list] 类定义为

AttributeDictionary

但收到错误

class AttributeDictionary(dict, json_mixin.JsonMixin):
    def __new__(cls, *args, **kwargs):
        obj = super(AttributeDictionary, cls).__new__(cls, *args, **kwargs)
        obj.attr1 = []
        return obj

    def __init__(self, manager=None, *args, **kwargs):
        super(AttributeDictionary, self).__init__(*args, **kwargs)
        self.__dict__ = self

        if manager:
            self.process_safe_dict = manager.dict()

    def has(self, obj_name):
        return obj_name in list(self.__dict__.keys())

TypeError: unhashable type: 'list' 中的示例AttributeDictionary定义为,

att_dict_list

并说我要删除密钥 {'a': [[ObjectId('5a8ec91ef1c63e2266f0d62b'), 2018600046.0], [ObjectId('5a8ec91ef1c63e2266f0d62a'), 2010600047.0]], 'b': [[ObjectId('5a8ec91ef1c63e2257f0ccbd'), 2011601057.0], [ObjectId('5a8ec91ef1c63e2257f0bde3'), 2019601058.0]], 'e': [ [[ObjectId('5a8ec91ef1c63e2257f0ccbd'), 2019601057.0], [ObjectId('5a8ec91ef1c63e2257f0bde3'), 2019601058.0]], [[ObjectId('5a8ec91ef1c63e225cf0b240'), 2014601177.0], [ObjectId('5a8ec91ef1c63e225cf0b23f'), 2013601178.0]], [[ObjectId('5a8ec91ef1c63e225cf0bc4c'), 2012601192.0], [ObjectId('5a8ec91ef1c63e225cf0bc4b'), 2011601193.0]], [[ObjectId('5a8ec91ef1c63e225cf0cb09'), 2013601216.0]] ], 'f': 109, 'c': [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], 'd': [2010601086.0, 2011601085.0, 2012601084.0] } ab

完全追溯

e

我想知道如何解决这个问题。

0 个答案:

没有答案