def listify(func=None, wrapper=list):
def _listify_return(func):<EOL><INDENT>@functools.wraps(func)<EOL>def _listify_helper(*args, **kw):<EOL><INDENT>return wrapper(func(*args, **kw))<EOL><DEDENT>return _listify_helper<EOL><DEDENT>if func is None:<EOL><INDENT>return _listify_return<EOL><DEDENT>return _listify_return(func)<EOL>
A decorator which wraps a function's return value in ``list(...)``.
Useful when an algorithm can be expressed more cleanly as a generator but
the function should return an list.
Example::
    >>> @listify
    ... def get_lengths(iterable):
    ...     for i in iterable:
    ...         yield len(i)
    >>> get_lengths(["spam", "eggs"])
    [4, 4]
    >>>
    >>> @listify(wrapper=tuple)
    ... def get_lengths_tuple(iterable):
    ...     for i in iterable:
    ...         yield len(i)
    >>> get_lengths_tuple(["foo", "bar"])
    (3, 3)