python array form input
Question: in Python input is `[[1,2,3],[2,3,4]]` form

not like integer form 1 2 3 2 3 4

but having []

in code

    
    
    input =[]
    inputfunc() //get input array
    print input
    

You input

    
    
    [[1,2,3],[2,3,4]]
    

python result will print

    
    
    [[1,2,3],[2,3,4]]
    

So can I save this variable? or I must using String parsing?


Answer: You can use
[`ast.literal_eval()`](https://docs.python.org/2/library/ast.html?highlight=literal_eval#ast.literal_eval)
to convert that string into a python object like this:

    
    
    >>> import ast
    >>> ast.literal_eval('[[1,2,3],[2,3,4]]')
    [[1, 2, 3], [2, 3, 4]]
    >>> L=ast.literal_eval('[[1,2,3],[2,3,4]]')
    >>> type(L)
    <class 'list'>
    >>> L
    [[1, 2, 3], [2, 3, 4]]
    >>>
    

`ast` stands for Abstract Syntax Tree. `literal_eval()` is much more safe than
`eval()`.

Quoting from official doc:

> ast.literal_eval(node_or_string) Safely evaluate an expression node or a
> Unicode or Latin-1 encoded string containing a Python literal or container
> display. The string or node provided may only consist of the following
> Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
> and None.
>
> This can be used for safely evaluating strings containing Python values from
> untrusted sources without the need to parse the values oneself. It is not
> capable of evaluating arbitrarily complex expressions, for example involving
> operators or indexing.

