Fix nth() itertool recipe.

This commit is contained in:
Georg Brandl 2006-10-28 16:04:04 +00:00
parent 0b679629c6
commit 35692a0c0e
1 changed files with 2 additions and 2 deletions

View File

@ -474,8 +474,8 @@ def iteritems(mapping):
return izip(mapping.iterkeys(), mapping.itervalues())
def nth(iterable, n):
"Returns the nth item"
return list(islice(iterable, n, n+1))
"Returns the nth item or raise IndexError"
return list(islice(iterable, n, n+1))[0]
def all(seq, pred=None):
"Returns True if pred(x) is true for every element in the iterable"