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

Method update

sortedcontainers/sortedset.py:664–692  ·  view source on GitHub ↗

Update the sorted set adding values from all `iterables`. The `update` method also corresponds to operator ``|=``. ``ss.__ior__(iterable)`` <==> ``ss |= iterable`` >>> ss = SortedSet([1, 2, 3, 4, 5]) >>> _ = ss.update([4, 5, 6, 7]) >>> ss SortedSet(

(self, *iterables)

Source from the content-addressed store, hash-verified

662
663
664 def update(self, *iterables):
665 """Update the sorted set adding values from all `iterables`.
666
667 The `update` method also corresponds to operator ``|=``.
668
669 ``ss.__ior__(iterable)`` <==> ``ss |= iterable``
670
671 >>> ss = SortedSet([1, 2, 3, 4, 5])
672 >>> _ = ss.update([4, 5, 6, 7])
673 >>> ss
674 SortedSet([1, 2, 3, 4, 5, 6, 7])
675
676 :param iterables: iterable arguments
677 :return: itself
678
679 """
680 _set = self._set
681 _list = self._list
682 values = set(chain(*iterables))
683 if (4 * len(values)) > len(_set):
684 _list = self._list
685 _set.update(values)
686 _list.clear()
687 _list.update(_set)
688 else:
689 _add = self._add
690 for value in values:
691 _add(value)
692 return self
693
694 __ior__ = update
695 _update = update

Callers 7

stress_issubsetFunction · 0.95
test_isliceFunction · 0.95
test_irangeFunction · 0.95
test_updateFunction · 0.95
difference_updateMethod · 0.45
intersection_updateMethod · 0.45

Calls 1

clearMethod · 0.45

Tested by 4

stress_issubsetFunction · 0.76
test_isliceFunction · 0.76
test_irangeFunction · 0.76
test_updateFunction · 0.76