本文整理汇总了Python中sortedcontainers.SortedKeyList.add方法的典型用法代码示例。如果您正苦于以下问题:Python SortedKeyList.add方法的具体用法?Python SortedKeyList.add怎么用?Python SortedKeyList.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedKeyList
的用法示例。
在下文中一共展示了SortedKeyList.add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_copy():
slt = SortedKeyList(range(100), key=modulo)
slt._reset(7)
two = slt.copy()
slt.add(100)
assert len(slt) == 101
assert len(two) == 100
示例2: test_copy_copy
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_copy_copy():
import copy
slt = SortedKeyList(range(100), key=negate)
slt._reset(7)
two = copy.copy(slt)
slt.add(100)
assert len(slt) == 101
assert len(two) == 100
示例3: test_key2
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_key2():
class Incomparable:
pass
a = Incomparable()
b = Incomparable()
slt = SortedKeyList(key=lambda val: 1)
slt.add(a)
slt.add(b)
assert slt == [a, b]
示例4: test_count
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_count():
slt = SortedKeyList(key=negate)
slt._reset(7)
assert slt.count(0) == 0
for iii in range(100):
for jjj in range(iii):
slt.add(iii)
slt._check()
for iii in range(100):
assert slt.count(iii) == iii
示例5: test_count
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_count():
slt = SortedKeyList(key=modulo)
slt._reset(7)
assert slt.count(0) == 0
for iii in range(100):
for jjj in range(iii):
slt.add(iii)
slt._check()
for iii in range(100):
assert slt.count(iii) == iii
slt = SortedKeyList(range(8), key=modulo)
assert slt.count(9) == 0
示例6: test_getitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_getitem():
random.seed(0)
slt = SortedKeyList(key=modulo)
slt._reset(17)
slt.add(5)
slt._build_index()
slt._check()
slt.clear()
lst = list(random.random() for rpt in range(100))
slt.update(lst)
lst.sort(key=modulo)
assert all(slt[idx] == lst[idx] for idx in range(100))
assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
示例7: test_getitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_getitem():
random.seed(0)
slt = SortedKeyList(key=negate)
slt._reset(17)
slt.add(5)
assert slt[0] == 5
slt.clear()
lst = list()
for rpt in range(100):
val = random.random()
slt.add(val)
lst.append(val)
lst.sort(reverse=True)
assert all(slt[idx] == lst[idx] for idx in range(100))
assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
示例8: test_getitem_slice
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_getitem_slice():
random.seed(0)
slt = SortedKeyList(key=modulo)
slt._reset(17)
lst = list()
for rpt in range(100):
val = random.random()
slt.add(val)
lst.append(val)
lst.sort(key=modulo)
assert all(slt[start:] == lst[start:]
for start in [-75, -25, 0, 25, 75])
assert all(slt[:stop] == lst[:stop]
for stop in [-75, -25, 0, 25, 75])
assert all(slt[::step] == lst[::step]
for step in [-5, -1, 1, 5])
assert all(slt[start:stop] == lst[start:stop]
for start in [-75, -25, 0, 25, 75]
for stop in [-75, -25, 0, 25, 75])
assert all(slt[:stop:step] == lst[:stop:step]
for stop in [-75, -25, 0, 25, 75]
for step in [-5, -1, 1, 5])
assert all(slt[start::step] == lst[start::step]
for start in [-75, -25, 0, 25, 75]
for step in [-5, -1, 1, 5])
assert all(slt[start:stop:step] == lst[start:stop:step]
for start in [-75, -25, 0, 25, 75]
for stop in [-75, -25, 0, 25, 75]
for step in [-5, -1, 1, 5])
示例9: test_add
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_add():
random.seed(0)
slt = SortedKeyList(key=modulo)
for val in range(1000):
slt.add(val)
slt._check()
slt = SortedKeyList(key=modulo)
for val in range(1000, 0, -1):
slt.add(val)
slt._check()
slt = SortedKeyList(key=modulo)
for val in range(1000):
slt.add(random.random())
slt._check()
示例10: test_len
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import add [as 别名]
def test_len():
slt = SortedKeyList(key=modulo)
for val in range(10000):
slt.add(val)
assert len(slt) == (val + 1)