子衿沉夜
您可以使用一维字典并在一个字符串中合并 itme 和不好的年份,您宁愿使用二维字典并首先填充空列表,然后通过两个信息访问:项目+日期一个项目然后一年values = {i: {year: [] for year in years} for i in info}{'played_games': {'2020': [], '2019': [], '2018': [], '2017': [], '2016': [], '2015': [], '2014': [], '2013': []}, 'games_won': {'2020': [], '2019': [], '2018': [], '2017': [], '2016': [], '2015': [], '2014': [], '2013': []}, 'efectivity': {'2020': [], '2019': [], '2018': [], '2017': [], '2016': [], '2015': [], '2014': [], '2013': []}, ...}# add data likevalues["played_games"]['2014'].append("foo")一年然后一个项目values = {year: {i: [] for i in info} for year in years}{'2020': {'played_games': [], 'games_won': [], 'efectivity': [], 'championship_won': [], 'finals': [], 'semi-finals': [], 'quarterfinals': []}, '2019': {'played_games': [], 'games_won': [], 'efectivity': [], 'championship_won': [], 'finals': [], 'semi-finals': [], 'quarterfinals': []}, '2018': {'played_games': [], 'games_won': [], 'efectivity': [], 'championship_won': [], 'finals': [], 'semi-finals': [], 'quarterfinals': []}, ...}# add data likevalues['2014']["played_games"].append("foo")
慕标5832272
使用 2 个循环,你可以试试这个:years = ["2020", "2019", "2018", "2017", "2016", "2015", "2014", "2013"]info = ["played_games", "games_won", "efectivity", "championship_won", "finals", "semi-finals", "quarterfinals"]all_arrays_dict = {}for x in years: for y in info: all_arrays_dict[y+x] = []print(all_arrays_dict)这是输出字典:{ "played_games2020": [], "games_won2020": [], "efectivity2020": [], "championship_won2020": [], "finals2020": [], "semi-finals2020": [], "quarterfinals2020": [], "played_games2019": [], "games_won2019": [], . . .}