mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
...
This commit is contained in:
parent
4b00846861
commit
2f3017ebfd
@ -20,6 +20,9 @@ class defaultdict:
|
|||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
self._a[key] = value
|
self._a[key] = value
|
||||||
|
|
||||||
|
def __delitem__(self, key):
|
||||||
|
del self._a[key]
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"defaultdict({self.default_factory}, {self._a})"
|
return f"defaultdict({self.default_factory}, {self._a})"
|
||||||
|
|
||||||
@ -50,3 +53,17 @@ class defaultdict:
|
|||||||
|
|
||||||
def pop(self, *args):
|
def pop(self, *args):
|
||||||
return self._a.pop(*args)
|
return self._a.pop(*args)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self._a.clear()
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
new_dd = defaultdict(self.default_factory)
|
||||||
|
new_dd._a = self._a.copy()
|
||||||
|
return new_dd
|
||||||
|
|
||||||
|
def get(self, key, default):
|
||||||
|
return self._a.get(key, default)
|
||||||
|
|
||||||
|
def update(self, other):
|
||||||
|
self._a.update(other)
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
from collections import Counter, deque
|
from collections import Counter, deque, defaultdict
|
||||||
import random
|
import random
|
||||||
import pickle
|
import pickle
|
||||||
import gc
|
import gc
|
||||||
import builtins
|
import builtins
|
||||||
|
|
||||||
|
dd_dict_keys = sorted(defaultdict.__dict__.keys())
|
||||||
|
d_dict_keys = sorted(dict.__dict__.keys())
|
||||||
|
d_dict_keys.remove('__new__')
|
||||||
|
if dd_dict_keys != d_dict_keys:
|
||||||
|
print("dd_dict_keys:", dd_dict_keys)
|
||||||
|
print("d_dict_keys:", d_dict_keys)
|
||||||
|
raise Exception("dd_dict_keys != d_dict_keys")
|
||||||
|
|
||||||
q = deque()
|
q = deque()
|
||||||
q.append(1)
|
q.append(1)
|
||||||
q.append(2)
|
q.append(2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user