Dictionary 具有嵌套列表的字典中的For循环

Dictionary 具有嵌套列表的字典中的For循环,dictionary,for-loop,nested-lists,Dictionary,For Loop,Nested Lists,我想有效地替换某些变量(问题16_a、问题16_b和问题16_c)中的一些值,我创建了一个字典,将问题的名称作为键,并将嵌套列表作为值,嵌套列表中的第一个列表是我要替换的值,第二个列表包含我要替换的值 dict_1={"question_16_a":[["Un assemblage de cépages","Ugni blanc","UNIBLANC","ugni blanc","un

我想有效地替换某些变量(问题16_a、问题16_b和问题16_c)中的一些值,我创建了一个字典,将问题的名称作为键,并将嵌套列表作为值,嵌套列表中的第一个列表是我要替换的值,第二个列表包含我要替换的值

 dict_1={"question_16_a":[["Un assemblage de cépages","Ugni blanc","UNIBLANC","ugni blanc","uni-blanc","Petit Manseng","Rolle","Chenin"],["blend_of_grape_varieties","Ugni-blanc","Ugni-blanc","Ugni-blanc","Ugni-blanc","Other","Other","Other"]],"question_16_b":[["CHASSELAS","Chasselas / Pinot Gris"],["Chasselas","Chasselas"]],"question_16_c":[["MUSCADELLE","muscadelle","Muller Thurgau","Xinisteri indigenous grape variery","vERMENTINO","pinot noir"],["Muscadelle","Muscadelle","Other","Other","Other","Other"]],"question_16_d":[["MUSCADELLE","Rousanne"],["Muscadelle","Other"]]}
我这样做的循环,但它不工作

for keys,value in dict_1:
            df1[keys]=df1[keys].replace(value[0],value[1])
我有一个错误:

ValueError: too many values to unpack (expected 2)

我终于想出了这个办法,我觉得效果不错。 我将dict_1和dict_2中的dict_1分开,现在dict_1中的列表就是我要替换的值。dict_2中的列表是要替换的值

 dict_1={"question_16_a":["Un assemblage de cépages","Ugni blanc","UNIBLANC","ugni blanc","uni-blanc","Petit Manseng","Rolle","Chenin"],"question_16_b":["CHASSELAS","Chasselas / Pinot Gris"],"question_16_c":["MUSCADELLE","muscadelle","Muller Thurgau","Xinisteri indigenous grape variery","vERMENTINO","pinot noir"],"question_16_d":["MUSCADELLE","Rousanne"]}

dict_2={"question16_a":["blend_of_grape_varieties","Ugni-blanc","Ugni-blanc","Ugni-blanc","Ugni-blanc","Other","Other","Other"],"question_16_b":["Chasselas","Chasselas"],"question_16_c":["Muscadelle","Muscadelle","Other","Other","Other","Other"],"question_16_d":["Muscadelle","Other"]}

for (k,v),(k2,v2) in zip(dict_1.items(),dict_2.items()):
    df1[k]=df1[k].replace(v,v2)