dic = dict(zip(
["a", "b"],
["h", "i"]
))
lis_color = ["lightred"]
for key in dic.keys():
# 问题1: 判断键名是字典第几个键
ind = list(dic.keys()).index(key)
# 问题2: 根据索引循环选择颜色
color = lis_color[ind % len(lis_color)]
print(key, color)
标签:zip,color,dic,keys,key,lis,ind
From: https://blog.51cto.com/u_16055028/9199289