I have a nested dictionary that looks like this:
{
1: {'Name': {'John'}, 'Answer': {'yes'}, 'Country': {'USA'}},
2: {'Name': {'Julia'}, 'Answer': {'no'}, 'Country': {'Hong Kong'}}
3: {'Name': {'Adam'}, 'Answer': {'yes'}, 'Country': {'Hong Kong'}}
}
I now need to get the occurrence of each country and the number of people who answered yes or no. Currently, I only collect the number of occurrences in each country:
nationalities = ['USA', 'Hong Kong', 'France' ...]
for countries in nationalities:
cnt =[item for l in [v2 for v1 in dictionary1.values() for v2 in v1.values()] for item in l].count(countries)
result.append(countries + ': ' + str(cnt))
so using my datasheet I get something like
['Hong Kong: 2', 'France: 2', 'Italy: 3']
However, I would like to get the proportion of the people who answered yes and who answered no. Such that I get a list in the form of ['Hong Kong: 2 1 1']
where the first number would be total and the second and third would be yes and no respectively
Thanks for any help