def listify(gen):
"Convert a generator into a function which returns a list"
def patched(*args, **kwargs):
return list(gen(*args, **kwargs))
return patched
@listify
def f(x):
for i in range(x):
yield "item" + str(i)
assert f(5) == "item0 item1 item2 item3 item4".split()