2

I am pretty confused here. I have a function that has a list as an argument. It then does list-specific functions on it. Here is an example:

def getValues( my_list ):
    for q in my_list:
        print(q)

But, I get my list from USER INPUT like this:

a_list = input("Please enter a list.  ")
getValues(a_list)

The built-in input() function returns a string, not a list. My solution is to take that string of the list and turn it back into a list.

Only I don't know how.

Thanks!

Blue
  • 545
  • 3
  • 13

1 Answers1

5

Its what that ast.literal_eval is for :

>>> ast.literal_eval('[1,2,3]')
[1, 2, 3]
Mazdak
  • 105,000
  • 18
  • 159
  • 188