python统计多个字典里某个键是特定值的键的个数

python统计多个字典里某个键是特定值的键的个数

fav_colors = {"John": {"a":"green","b":"green"}, "Bobby":{"a":"red","b":"yellow"}, "PapaSanta":{"a":"red","b":"green"},“Jack”:{"a":"black","b":"yellow"}}

怎么统计fav_colors里套的字典里"b"的值是"green"的个数


回答:

python3">fav_colors = {"John": {"a":"green","b":"green"}, "Bobby":{"a":"red","b":"yellow"}, "PapaSanta":{"a":"red","b":"green"},"Jack":{"a":"black","b":"yellow"}}

g=0

for a in fav_colors.keys():

if (fav_colors[a]["b"] =="green") :

g=g+1

print(g)

以上是 python统计多个字典里某个键是特定值的键的个数 的全部内容, 来源链接: utcz.com/p/938177.html

回到顶部