"Return first n items of the iterable as a list"
return list(islice(iterable, n))
+ def prepend(value, iterator):
+ "Prepend a single value in front of an iterator"
+ # prepend(1, [2, 3, 4]) -> 1 2 3 4
+ return chain([value], iterator)
+
def tabulate(function, start=0):
"Return function(0), function(1), ..."
return map(function, count(start))
... "Return first n items of the iterable as a list"
... return list(islice(iterable, n))
+>>> def prepend(value, iterator):
+... "Prepend a single value in front of an iterator"
+... # prepend(1, [2, 3, 4]) -> 1 2 3 4
+... return chain([value], iterator)
+
>>> def enumerate(iterable, start=0):
... return zip(count(start), iterable)
>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+>>> list(prepend(1, [2, 3, 4]))
+[1, 2, 3, 4]
+
>>> list(enumerate('abc'))
[(0, 'a'), (1, 'b'), (2, 'c')]