MCPcopy Index your code
hub / github.com/grantjenks/python-sortedcontainers / remove

Method remove

sortedcontainers/sortedlist.py:426–462  ·  view source on GitHub ↗

Remove `value` from sorted list; `value` must be a member. If `value` is not a member, raise ValueError. Runtime complexity: `O(log(n))` -- approximate. >>> sl = SortedList([1, 2, 3, 4, 5]) >>> sl.remove(5) >>> sl == [1, 2, 3, 4] True >>> sl

(self, value)

Source from the content-addressed store, hash-verified

424
425
426 def remove(self, value):
427 """Remove `value` from sorted list; `value` must be a member.
428
429 If `value` is not a member, raise ValueError.
430
431 Runtime complexity: `O(log(n))` -- approximate.
432
433 >>> sl = SortedList([1, 2, 3, 4, 5])
434 >>> sl.remove(5)
435 >>> sl == [1, 2, 3, 4]
436 True
437 >>> sl.remove(0)
438 Traceback (most recent call last):
439 ...
440 ValueError: 0 not in list
441
442 :param value: `value` to remove from sorted list
443 :raises ValueError: if `value` is not in sorted list
444
445 """
446 _maxes = self._maxes
447
448 if not _maxes:
449 raise ValueError('{0!r} not in list'.format(value))
450
451 pos = bisect_left(_maxes, value)
452
453 if pos == len(_maxes):
454 raise ValueError('{0!r} not in list'.format(value))
455
456 _lists = self._lists
457 idx = bisect_left(_lists[pos], value)
458
459 if _lists[pos][idx] == value:
460 self._delete(pos, idx)
461 else:
462 raise ValueError('{0!r} not in list'.format(value))
463
464
465 def _delete(self, pos, idx):

Callers 5

test_removeFunction · 0.95
test_remove_valueerror1Function · 0.95
test_remove_valueerror2Function · 0.95
test_remove_valueerror3Function · 0.95
test_deleteFunction · 0.95

Calls 1

_deleteMethod · 0.95

Tested by 5

test_removeFunction · 0.76
test_remove_valueerror1Function · 0.76
test_remove_valueerror2Function · 0.76
test_remove_valueerror3Function · 0.76
test_deleteFunction · 0.76