How to achieve the functionality of UserDict.DictMixin in Python 3?

前端 未结 1 835
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 20:34

In Python 3 the UserDict.DictMixin class was moved to the collections module. The docs suggest using collections.MutableMapping in its

相关标签:
1条回答
  • 2021-01-11 20:51

    The "number of methods" are specifically __len__ and __iter__ so the additional work is not that much.

    def __len__(self):
        return len(self.mylist)
    
    def __iter__(self):
        for i in self.mylist:
            yield i
    

    Should work, I think (untested, though).

    0 讨论(0)
提交回复
热议问题