Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions toolz/itertoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ def tail(n, seq):
drop
take
"""
if n == 0:
try:
return seq[:0]
except (TypeError, KeyError):
return ()
try:
return seq[-n:]
except (TypeError, KeyError):
Expand Down
5 changes: 5 additions & 0 deletions toolz/tests/test_itertoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ def test_tail():
assert list(tail(3, 'ABCDE')) == list('CDE')
assert list(tail(3, iter('ABCDE'))) == list('CDE')
assert list(tail(2, (3, 2, 1))) == list((2, 1))
assert tail(0, [10, 20, 30]) == []
assert list(tail(0, [10, 20, 30])) == []
assert tuple(tail(0, iter([10, 20, 30]))) == ()
assert tail(0, 'ABCDE') == ''
assert tail(0, (3, 2, 1)) == ()


def test_drop():
Expand Down