mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
feat: add Dict.concat/diff
, Dict!.merge!/remove!
This commit is contained in:
parent
73958a3e56
commit
13a346e488
11 changed files with 223 additions and 6 deletions
|
@ -1,2 +1,18 @@
|
|||
class Dict(dict):
|
||||
pass
|
||||
def concat(self, other):
|
||||
return Dict({**self, **other})
|
||||
def diff(self, other):
|
||||
return Dict({k: v for k, v in self.items() if k not in other})
|
||||
# other: Iterable
|
||||
def extend(self, other):
|
||||
self.update(other)
|
||||
# other: Dict
|
||||
def merge(self, other):
|
||||
self.update(other)
|
||||
def insert(self, key, value):
|
||||
self[key] = value
|
||||
def remove(self, key):
|
||||
res = self.get(key)
|
||||
if res != None:
|
||||
del self[key]
|
||||
return res
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue