MCPcopy Create free account
hub / github.com/grantjenks/python-sortedcontainers / update

Method update

sortedcontainers/sorteddict.py:545–574  ·  view source on GitHub ↗

Update sorted dict with items from `args` and `kwargs`. Overwrites existing items. Optional arguments `args` and `kwargs` may be a mapping, an iterable of pairs or keyword arguments. See :func:`SortedDict.__init__` for details. :param args: mapping or itera

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

543
544
545 def update(self, *args, **kwargs):
546 """Update sorted dict with items from `args` and `kwargs`.
547
548 Overwrites existing items.
549
550 Optional arguments `args` and `kwargs` may be a mapping, an iterable of
551 pairs or keyword arguments. See :func:`SortedDict.__init__` for
552 details.
553
554 :param args: mapping or iterable of pairs
555 :param kwargs: keyword arguments mapping
556
557 """
558 if not self:
559 dict.update(self, *args, **kwargs)
560 self._list_update(dict.__iter__(self))
561 return
562
563 if not kwargs and len(args) == 1 and isinstance(args[0], dict):
564 pairs = args[0]
565 else:
566 pairs = dict(*args, **kwargs)
567
568 if (10 * len(pairs)) > len(self):
569 dict.update(self, pairs)
570 self._list_clear()
571 self._list_update(dict.__iter__(self))
572 else:
573 for key in pairs:
574 self._setitem(key, pairs[key])
575
576 _update = update
577

Callers 5

test_updateFunction · 0.95
test_update2Function · 0.95
test_keysviewFunction · 0.95
test_valuesviewFunction · 0.95
test_itemsviewFunction · 0.95

Calls 1

__iter__Method · 0.45

Tested by 5

test_updateFunction · 0.76
test_update2Function · 0.76
test_keysviewFunction · 0.76
test_valuesviewFunction · 0.76
test_itemsviewFunction · 0.76