本文整理匯總了Python中sortedcontainers.SortedList.bisect_left方法的典型用法代碼示例。如果您正苦於以下問題:Python SortedList.bisect_left方法的具體用法?Python SortedList.bisect_left怎麽用?Python SortedList.bisect_left使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sortedcontainers.SortedList
的用法示例。
在下文中一共展示了SortedList.bisect_left方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_bisect_left
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import bisect_left [as 別名]
def test_bisect_left():
slt = SortedList()
assert slt.bisect_left(0) == 0
slt = SortedList(range(100), load=17)
slt.update(range(100))
slt._check()
assert slt.bisect_left(50) == 100
assert slt.bisect_left(200) == 200
示例2: PriorityDict
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import bisect_left [as 別名]
#.........這裏部分代碼省略.........
Update the dictionary with the key/value pairs from *other*, overwriting
existing keys.
*update* accepts either another dictionary object or an iterable of
key/value pairs (as a tuple or other iterable of length two). If
keyword arguments are specified, the dictionary is then updated with
those key/value pairs: ``d.update(red=1, blue=2)``.
"""
_list, _dict = self._list, self._dict
if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], Mapping):
items = args[0]
else:
items = dict(*args, **kwargs)
if (10 * len(items)) > len(_dict):
_dict.update(items)
_list.clear()
_list.update((value, key) for key, value in iteritems(_dict))
else:
for key, value in iteritems(items):
old_value = _dict[key]
_list.remove((old_value, key))
_dict[key] = value
_list.add((value, key))
def index(self, key):
"""
Return the smallest *i* such that `d.iloc[i] == key`. Raises KeyError
if *key* is not present.
"""
value = self._dict[key]
return self._list.index((value, key))
def bisect_left(self, value):
"""
Similar to the ``bisect`` module in the standard library, this returns
an appropriate index to insert *value* in PriorityDict. If *value* is
already present in PriorityDict, the insertion point will be before (to
the left of) any existing entries.
"""
return self._list.bisect_left((value,))
def bisect(self, value):
"""Same as bisect_left."""
return self._list.bisect((value,))
def bisect_right(self, value):
"""
Same as `bisect_left`, but if *value* is already present in
PriorityDict, the insertion point will be after (to the right
of) any existing entries.
"""
return self._list.bisect_right((value, _Biggest))
def __iadd__(self, that):
"""Add values from `that` mapping."""
_list, _dict = self._list, self._dict
if len(_dict) == 0:
_dict.update(that)
_list.update((value, key) for key, value in iteritems(_dict))
elif len(that) * 3 > len(_dict):
_list.clear()
for key, value in iteritems(that):
if key in _dict:
_dict[key] += value
else: