Skip to content

Commit 68d8df8

Browse files
authored
Merge pull request #408 from groutr/faster-second
Avoid islice overhead in itertoolz.second
2 parents 2c1dabb + 307b0bb commit 68d8df8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

toolz/itertoolz.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ def second(seq):
380380
>>> second('ABC')
381381
'B'
382382
"""
383-
return next(itertools.islice(seq, 1, None))
383+
seq = iter(seq)
384+
next(seq)
385+
return next(seq)
384386

385387

386388
def nth(n, seq):

0 commit comments

Comments
 (0)