In [1]:
%autosave 10
(wait for IPython Notebook to get posted)
In [2]:
def f(x):
return x+1, x+2
f(10) == (11, 12)
Out[2]:
In [3]:
def f(x):
yield x+1
yield x+2
list(f(10)) == [11, 12]
Out[3]:
Generators require iteration over results.
In [4]:
class Callable(object):
def __call__(self, x):
return x+1, x+2
Callable()(10) == (11, 12)
Out[4]:
In [8]:
def generator(x):
y = None
y = yield x+1, y
y = yield x+1, y
g = generator(10)
print g.next()
print g.send("abc")
izip, islice help you manipulate iterables without caring about their contents.chain just connects iterables, doesn't care.
In [ ]: