I have a list called x
:
import numpy as np
import pandas as pd
x = ['feature1', 'feature2', 'feature3', 'feature4']
I need to initialize each element of that list (without the quote '
) like this:
feature1 = ''
feature2 = ''
feature3 = ''
feature4 = ''
Is there a pythonic way of doing so, without having to manually write each element? I am asking because I have a list of 5,783 elements and I cannot write them down manually.
CodePudding user response:
Use:
for y in x:
exec("%s = ''" % (y))
Output: