从列表python的字符串中获取原始列表

Blu*_*lue 2 python input list

我在这里很困惑.我有一个列表作为参数的函数.然后它会在其上执行特定于列表的功能.这是一个例子:

def getValues( my_list ):
    for q in my_list:
        print(q)
Run Code Online (Sandbox Code Playgroud)

但是,我从USER INPUT获取我的列表,如下所示:

a_list = input("Please enter a list.  ")
getValues(a_list)
Run Code Online (Sandbox Code Playgroud)

内置的input()函数返回一个字符串,而不是一个列表.我的解决方案是获取列表中的该字符串并将其转回列表.

只有我不知道怎么做.

谢谢!

Kas*_*mvd 5

它的ast.literal_eval用途是:

>>> ast.literal_eval('[1,2,3]')
[1, 2, 3]
Run Code Online (Sandbox Code Playgroud)