human
Complete this python program:
def literal_eval(node_or_string):
assistant
#Here is the Python code you requested.

    """Safely evaluate an expression node or a string containing a Python
    expression.  The string or node provided may only consist of the following
    Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
    and None.
    """
    _safe_names = {'None': None, 'True': True, 'False': False}
    if isinstance(node_or_string, basestring):
        node_or_string = parse(node_or_string, mode='eval')
    if isinstance(node_or_string, Expression):
        node_or_string = node_or_string.body
    def _convert(node):
        if isinstance(node, Str):
            return node.s
        if isinstance(node, Num):
            return node.n
        if isinstance(node, Tuple):
            return tuple(map(_convert, node.elts))
        if isinstance(node, List):
            return list(map(_convert, node.elts))
        if isinstance(node, Dict):
            return dict(((_convert(k), _convert(v)) for (k, v) in zip(node.keys, node.values)))
        if isinstance(node, Name):
            if (node.id in _safe_names):
                return _safe_names[node.id]
        elif (isinstance(node, BinOp) and isinstance(node.op, (Add, Sub)) and isinstance(node.right, Num) and isinstance(node.right.n, complex) and isinstance(node.left, Num)):
            if isinstance(node.left.n, (int, long, float)):
                left = node.left.n
                right = node.right.n
                if isinstance(node.op, Add):
                    return (left + right)
                return (left - right)
        raise ValueError('malformed    string')
    return _convert(node_or_string)