Let's say I have the dict below
{
"1": {
"rarity": 1
},
"2": {
"rarity": 2
}
}
and I want to find the amount of times rarity
is 1. Instead of doing
count = 0
for x in dict.values():
if x['rarity'] == 1:
count += 1
return count
Is there a better way to do this? I found this post about using map
, but I'm not sure how to get it to work with a nested dictionary.