diff --git a/toolz/itertoolz.py b/toolz/itertoolz.py index 354ecf25..00541639 100644 --- a/toolz/itertoolz.py +++ b/toolz/itertoolz.py @@ -522,10 +522,10 @@ def interpose(el, seq): >>> list(interpose("a", [1, 2, 3])) [1, 'a', 2, 'a', 3] + >>> list(interpose("a", [])) + [] """ - inposed = concat(zip(itertools.repeat(el), seq)) - next(inposed) - return inposed + return drop(1, concat(zip(itertools.repeat(el), seq))) def frequencies(seq): diff --git a/toolz/tests/test_itertoolz.py b/toolz/tests/test_itertoolz.py index c8640917..83f6dd5e 100644 --- a/toolz/tests/test_itertoolz.py +++ b/toolz/tests/test_itertoolz.py @@ -253,6 +253,8 @@ def test_interpose(): 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'] + assert list(interpose("a", [])) == [] + assert list(interpose("a", [1])) == [1] def test_frequencies():