Python List as variable name

后端 未结 2 1345
花落未央
花落未央 2020-12-28 11:03

I\'ve been playing with Python and I have this list that I need worked out. Basically I type a list of games into the multidimensional array and then for each one, it will m

2条回答
  •  醉话见心
    2020-12-28 11:43

    It would be easiest to do this with a dictionary:

    app_list = [
        ['Apple', 'red', 'circle'],
        ['Banana', 'yellow', 'abnormal'],
        ['Pear', 'green', 'abnormal']
    ]
    app_keys = {}
    
    for sub_list in app_list:
        app_keys["%s_n" % sub_list[0]] = sub_list[0]
        app_keys["%s_c" % sub_list[0]] = sub_list[1]
        app_keys["%s_s" % sub_list[0]] = sub_list[2]
    

提交回复
热议问题