Esempio n. 1
0
def unique(items, key=None):
    '''It yields the unique items.

    The items must be sorted. It only compares contiguous items.
    '''

    return (first(groups[1]) for groups in groupby(items, key))
Esempio n. 2
0
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"]
Esempio n. 3
0
def test_first():
    assert first("ABCDE") == "A"
    assert first((3, 2, 1)) == 3
    assert isinstance(first({0: "zero", 1: "one"}), int)
Esempio n. 4
0
def test_first():
    assert first('ABCDE') == 'A'
    assert first((3, 2, 1)) == 3
Esempio n. 5
0
def test_interpose():
    assert "a" == first(rest(interpose("a", range(10000000000))))
    assert "tXaXrXzXaXn" == "".join(interpose("X", "tarzan"))
Esempio n. 6
0
def test_first():
    assert first('ABCDE') == 'A'
    assert first((3, 2, 1)) == 3
    assert isinstance(first({0: 'zero', 1: 'one'}), int)
Esempio n. 7
0
def test_first():
    assert first('ABCDE') == 'A'
    assert first((3, 2, 1)) == 3
Esempio n. 8
0
def test_interpose():
    assert "a" == first(rest(interpose("a", range(10000000000))))
    assert "tXaXrXzXaXn" == "".join(interpose("X", "tarzan"))