How to assign each element of a list to a separate variable?

前端 未结 7 1705
花落未央
花落未央 2020-12-01 14:12

if I have a list, say:

ll = [\'xx\',\'yy\',\'zz\']

and I want to assign each element of this list to a separate variable:

v         


        
相关标签:
7条回答
  • 2020-12-01 14:51

    I have found a decent application for it. I have a bunch of csv files which I want to save as a dataframe under their name:

    all_files = glob.glob(path + "/*.csv")
    name_list = []
    for f in all_files:
        name_list.append(f[9:-4])
    for i,n in enumerate(name_list):
        globals()[n] = pd.read_csv(all_files[i])
    
    0 讨论(0)
提交回复
热议问题