I'm quite new to Python and overall programming so bear with me.
What I have is a dictionary of ['Male', 'Female', 'Eunuch']
as values and different names for these as keys:
Persons = { 'Hodor' : 'Male', 'Tyrion': 'Male', 'Theon': 'Male', 'Arya': 'Female', 'Daenerys': 'Female', 'Sansa': 'Female', 'Varys': 'Eunuch}
I want to order them into { Gender: {Names: Counts}}
As such:
input:
lst = ['Hodor', 'Hodor', 'Tyrion', 'Tyrion', 'Tyrion', 'Arya', 'Daenerys', 'Daenerys', 'Varys']
output:
{'Male': {'Hodor': 2, 'Tyrion': 3, Theon: 0}, 'Female': {'Arya': 1, 'Daenerys': 2, 'Sansa': 0}, 'Eunuch': {'Varys': 1}}
The first thing I have tried is making a code for counting:
counts = {}
for key in Persons:
counts[key] = 0
for key in lst:
counts[key] += 1
My dictionary D now contains the counts, but how do I compute them all together?
Names = Persons.keys()
Gender = Persons.values()
Counts = counts.values()
Names = counts.keys()
If varys isn't mentioned the gender 'Eunuch' shouldn't be in the output. I've tried different things, but when I try to connect them. I try to switch keys with values, but then only one name comes up.
Hope it makes sense of what I want to do :)
Edit: If Sansa isn't mention and other females are her value should be 0. And I want to be able to manipulate the numbers. Say at what percentage is Hodor mentioned compared to all the males.