def nthword(n, sep=None):
    """
    Construct a function to return the nth word in a string. E.g.::

        >>> import petl as etl
        >>> s = 'foo bar'
        >>> f = etl.nthword(0)
        >>> f(s)
        'foo'
        >>> g = etl.nthword(1)
        >>> g(s)
        'bar'

    Intended for use with :func:`petl.transform.conversions.convert`.

    """

    return lambda s: s.split(sep)[n]