how to convert a list of strings into a list of variables?

Question:

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.

Asked By: James

||

Answers:

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)
Answered By: Tobias Molenaar

try this:

new_list=list(map(lambda x:eval(x),my_list))
Answered By: to_data
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.