I'm working in python. Is there a way to count how many times values in a dictionary are found with more than one key, and then return a count?
So if for example I had 50 values and I ran a script to do this, I would get a count that would look something like this:
1: 23
2: 15
3: 7
4: 5
The above would be telling me that 23 values appear in 1 key, 15 values appear in 2 keys, 7 values appear in 3 keys and 5 values appear in 4 keys.
Also, would this question change if there were multiple values per key in my dictionary?
Here is a sample of my dictionary (it's bacteria names):
{'0': ['Pyrobaculum'], '1': ['Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium', 'Mycobacterium'], '3': ['Thermoanaerobacter', 'Thermoanaerobacter'], '2': ['Helicobacter', 'Mycobacterium'], '5': ['Thermoanaerobacter', 'Thermoanaerobacter'], '4': ['Helicobacter'], '7': ['Syntrophomonas'], '6': ['Gelria'], '9': ['Campylobacter', 'Campylobacter'], '8': ['Syntrophomonas'], '10': ['Desulfitobacterium', 'Mycobacterium']}
So from this sample, there are 8 unique values, I the ideal feedback I would get be:
1:4
2:3
3:1
So 4 bacteria names are only in one key, 3 bacteria are found in two keys and 1 bacteria is found in three keys.
See Question&Answers more detail:
os