]> granicus.if.org Git - python/commitdiff
Fix nth() itertool recipe.
authorGeorg Brandl <georg@python.org>
Sat, 28 Oct 2006 16:04:07 +0000 (16:04 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 28 Oct 2006 16:04:07 +0000 (16:04 +0000)
 (backport from rev. 52497)

Doc/lib/libitertools.tex

index 20bbc8dd7643b0359cc95fa2eee59cb35d82d0b4..59fbd98844e8ad2f46e990bd8ef247a71cc9ab48 100644 (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"