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

Method remove

sortedcontainers/sortedlist.py:2001–2051  ·  view source on GitHub ↗

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

(self, value)

Source from the content-addressed store, hash-verified

1999
2000
2001 def remove(self, value):
2002 """Remove `value` from sorted-key list; `value` must be a member.
2003
2004 If `value` is not a member, raise ValueError.
2005
2006 Runtime complexity: `O(log(n))` -- approximate.
2007
2008 >>> from operator import neg
2009 >>> skl = SortedKeyList([1, 2, 3, 4, 5], key=neg)
2010 >>> skl.remove(5)
2011 >>> skl == [4, 3, 2, 1]
2012 True
2013 >>> skl.remove(0)
2014 Traceback (most recent call last):
2015 ...
2016 ValueError: 0 not in list
2017
2018 :param value: `value` to remove from sorted-key list
2019 :raises ValueError: if `value` is not in sorted-key list
2020
2021 """
2022 _maxes = self._maxes
2023
2024 if not _maxes:
2025 raise ValueError('{0!r} not in list'.format(value))
2026
2027 key = self._key(value)
2028 pos = bisect_left(_maxes, key)
2029
2030 if pos == len(_maxes):
2031 raise ValueError('{0!r} not in list'.format(value))
2032
2033 _lists = self._lists
2034 _keys = self._keys
2035 idx = bisect_left(_keys[pos], key)
2036 len_keys = len(_keys)
2037 len_sublist = len(_keys[pos])
2038
2039 while True:
2040 if _keys[pos][idx] != key:
2041 raise ValueError('{0!r} not in list'.format(value))
2042 if _lists[pos][idx] == value:
2043 self._delete(pos, idx)
2044 return
2045 idx += 1
2046 if idx == len_sublist:
2047 pos += 1
2048 if pos == len_keys:
2049 raise ValueError('{0!r} not in list'.format(value))
2050 len_sublist = len(_keys[pos])
2051 idx = 0
2052
2053
2054 def _delete(self, pos, idx):

Callers 12

test_removeFunction · 0.95
test_remove_valueerror1Function · 0.95
test_remove_valueerror2Function · 0.95
test_remove_valueerror3Function · 0.95
test_remove_valueerror4Function · 0.95
test_remove_valueerror5Function · 0.95
test_deleteFunction · 0.95
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 12

test_removeFunction · 0.76
test_remove_valueerror1Function · 0.76
test_remove_valueerror2Function · 0.76
test_remove_valueerror3Function · 0.76
test_remove_valueerror4Function · 0.76
test_remove_valueerror5Function · 0.76
test_deleteFunction · 0.76
test_removeFunction · 0.76
test_remove_valueerror1Function · 0.76
test_remove_valueerror2Function · 0.76
test_remove_valueerror3Function · 0.76
test_deleteFunction · 0.76