python 自定义字典

import time


class my_dict(dict):
    key_set_time = []

    def __setitem__(self, *args, **kwargs): # real signature unknown
        """ Set self[key] to value. """
        super(my_dict, self).__setitem__(args[0], args[1]);
        if args[0] not in self.key_set_time:
            self.key_set_time.append((len(self.key_set_time)+1, args[0]))
        pass


if __name__ == '__main__':
    dict_value = my_dict()
    dict_value['aa'] = 1
    print('dict_value:', dict_value)
    print(dict_value.key_set_time)

你可能感兴趣的:(python,前端,开发语言)