当前位置: 首页>>代码示例>>Python>>正文


Python compatibility.range函数代码示例

本文整理汇总了Python中toolz.compatibility.range函数的典型用法代码示例。如果您正苦于以下问题:Python range函数的具体用法?Python range怎么用?Python range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了range函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_key_as_getter

def test_key_as_getter():
    squares = [(i, i**2) for i in range(5)]
    pows = [(i, i**2, i**3) for i in range(5)]

    assert set(join(0, squares, 0, pows)) == set(join(lambda x: x[0], squares,
                                                      lambda x: x[0], pows))

    get = lambda x: (x[0], x[1])
    assert set(join([0, 1], squares, [0, 1], pows)) == set(join(get, squares,
                                                                get, pows))

    get = lambda x: (x[0],)
    assert set(join([0], squares, [0], pows)) == set(join(get, squares,
                                                          get, pows))
开发者ID:karansag,项目名称:toolz,代码行数:14,代码来源:test_itertoolz.py

示例2: test_mapcat

def test_mapcat():
    assert list(mapcat(identity, [[1, 2, 3], [4, 5, 6]])) == [1, 2, 3, 4, 5, 6]

    assert list(mapcat(reversed, [[3, 2, 1, 0], [6, 5, 4], [9, 8, 7]])) == list(range(10))

    inc = lambda i: i + 1
    assert [4, 5, 6, 7, 8, 9] == list(mapcat(partial(map, inc), [[3, 4, 5], [6, 7, 8]]))
开发者ID:joyrexus,项目名称:toolz,代码行数:7,代码来源:test_core.py

示例3: groupsizes

def groupsizes(total, len):
    """ Groups of length len that add up to total

    >>> from kanren.util import groupsizes
    >>> tuple(groupsizes(4, 2))
    ((1, 3), (2, 2), (3, 1))
    """
    if len == 1:
        yield (total,)
    else:
        for i in range(1, total - len + 1 + 1):
            for perm in groupsizes(total - i, len - 1):
                yield (i,) + perm
开发者ID:logpy,项目名称:logpy,代码行数:13,代码来源:util.py

示例4: test_random_sample

def test_random_sample():
    alist = list(range(100))

    assert list(random_sample(prob=1, seq=alist, random_state=2016)) == alist

    mk_rsample = lambda rs=1: list(random_sample(prob=0.1,
                                                 seq=alist,
                                                 random_state=rs))
    rsample1 = mk_rsample()
    assert rsample1 == mk_rsample()

    rsample2 = mk_rsample(1984)
    randobj = Random(1984)
    assert rsample2 == mk_rsample(randobj)

    assert rsample1 != rsample2

    assert mk_rsample(object) == mk_rsample(object)
    assert mk_rsample(object) != mk_rsample(object())
    assert mk_rsample(b"a") == mk_rsample(u"a")

    assert raises(TypeError, lambda: mk_rsample([]))
开发者ID:caioaao,项目名称:toolz,代码行数:22,代码来源:test_itertoolz.py

示例5: test_remove

def test_remove():
    r = remove(iseven, range(5))
    assert type(r) is not list
    assert list(r) == list(filter(isodd, range(5)))
开发者ID:joyrexus,项目名称:toolz,代码行数:4,代码来源:test_core.py

示例6: test_partition_all

def test_partition_all():
    assert list(partition_all(2, [1, 2, 3, 4])) == [(1, 2), (3, 4)]
    assert list(partition_all(3, range(5))) == [(0, 1, 2), (3, 4)]
    assert list(partition_all(2, [])) == []
开发者ID:joyrexus,项目名称:toolz,代码行数:4,代码来源:test_core.py

示例7: test_partition

def test_partition():
    assert list(partition(2, [1, 2, 3, 4])) == [(1, 2), (3, 4)]
    assert list(partition(3, range(7))) == [(0, 1, 2), (3, 4, 5)]
    assert list(partition(3, range(4), pad=-1)) == [(0, 1, 2), (3, -1, -1)]
    assert list(partition(2, [])) == []
开发者ID:joyrexus,项目名称:toolz,代码行数:5,代码来源:test_core.py

示例8: test_interpose

def test_interpose():
    assert "a" == first(rest(interpose("a", range(1000000000))))
    assert "tXaXrXzXaXn" == "".join(interpose("X", "tarzan"))
    assert list(interpose(0, itertools.repeat(1, 4))) == [1, 0, 1, 0, 1, 0, 1]
    assert list(interpose(".", ["a", "b", "c"])) == ["a", ".", "b", ".", "c"]
开发者ID:joyrexus,项目名称:toolz,代码行数:5,代码来源:test_core.py

示例9: test_concatv

def test_concatv():
    assert list(concatv([], [], [])) == []
    assert list(take(5, concatv(["a", "b"], range(1000000000)))) == ["a", "b", 0, 1, 2]
开发者ID:joyrexus,项目名称:toolz,代码行数:3,代码来源:test_core.py

示例10: test_concatv

def test_concatv():
    assert list(concatv([], [], [])) == []
    assert (list(take(5, concatv(['a', 'b'], range(1000000000)))) ==
            ['a', 'b', 0, 1, 2])
开发者ID:karansag,项目名称:toolz,代码行数:4,代码来源:test_itertoolz.py

示例11: test_remove

def test_remove():
    assert list(remove(even, range(5))) == list(filter(odd, range(5)))
开发者ID:JNRowe,项目名称:toolz,代码行数:2,代码来源:test_core.py

示例12: test_interpose

def test_interpose():
    assert "a" == first(rest(interpose("a", range(10000000000))))
    assert "tXaXrXzXaXn" == "".join(interpose("X", "tarzan"))
开发者ID:JNRowe,项目名称:toolz,代码行数:3,代码来源:test_core.py


注:本文中的toolz.compatibility.range函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。