def listify(values, N=1, delim=None):
    ans = [] if values is None else values
    if hasattr(ans, '__iter__') and not isinstance(ans, basestring):
        ans = list(ans)
    else:
        if isinstance(delim, basestring) and isinstance(ans, basestring):
            try:
                ans = ans.split(delim)
            except (IndexError, ValueError, AttributeError, TypeError):
                ans = [ans]
        else:
            ans = [ans]
    if len(ans):
        if len(ans) < N and N > 1:
            ans += [ans[-1]] * (N - len(ans))
    else:
        if N > 1:
            ans = [[]] * N
    return ans