def unbracket(args):
    "Convert input list with bracketed items into nested lists.\n\n    >>> unbracket('foo [ bar a b ] [ baz c ] -o z'.split())\n    ['foo', ['bar', 'a', 'b'], ['baz', 'c'], '-o', 'z']\n\n    "
    outargs = []
    stack = []
    mismatch_msg = 'Mismatched bracket at position %i.'
    for (i, arg) in enumerate(args):
        if (arg == '['):
            stack.append(outargs)
            outargs = []
        elif (arg == ']'):
            if (not stack):
                raise ValueError((mismatch_msg % i))
            stack[(- 1)].append(outargs)
            outargs = stack.pop()
        else:
            outargs.append(arg)
    if stack:
        raise ValueError((mismatch_msg % len(args)))
    return outargs
Convert input list with bracketed items into nested lists.

>>> unbracket('foo [ bar a b ] [ baz c ] -o z'.split())
['foo', ['bar', 'a', 'b'], ['baz', 'c'], '-o', 'z']
def unbracket(args):
    "Convert input list with bracketed items into nested lists.\n\n    >>> unbracket('foo [ bar a b ] [ baz c ] -o z'.split())\n    ['foo', ['bar', 'a', 'b'], ['baz', 'c'], '-o', 'z']\n\n    "
    outargs = []
    stack = []
    mismatch_msg = 'Mismatched bracket at position %i.'
    for (i, arg) in enumerate(args):
        if (arg == '['):
            stack.append(outargs)
            outargs = []
        elif (arg == ']'):
            if (not stack):
                raise ValueError((mismatch_msg % i))
            stack[(- 1)].append(outargs)
            outargs = stack.pop()
        else:
            outargs.append(arg)
    if stack:
        raise ValueError((mismatch_msg % len(args)))
    return outargs