Home > Blockchain >  how to convert a list of strings into a list of variables?
how to convert a list of strings into a list of variables?

Time:08-13

Hi might be a simple question. How do i convert this:

mylist = ['table[0].df', 'table[1].df']

to this

mylist = [table[0].df, table[1].df]

Thank you.

CodePudding user response:

Here is a possible solution using eval. For every item in the list, eval() is used and saved on the same location as the original string.

mylist = ['table[0].df', 'table[1].df']

for i, item in enumerate(mylist):
    mylist[i] = eval(item)

CodePudding user response:

try this:

new_list=list(map(lambda x:eval(x),my_list))
  • Related