Pythn count multiple values in dictionary of list
<p>I have been trying to count the values in a dictionary with respect to the key. However, I could not achieved desired result. I will demonstrate with more details below:</p>

<pre><code>from collections import Counter
d = {'a': ['Adam','Adam','John'], 'b': ['John','John','Joel'], 'c': ['Adam','Adam','John}
# create a list of only the values you want to count,
# and pass to Counter()
c = Counter([values[1] for values in d.itervalues()])
print c
</code></pre>

<p>My output:</p>

<pre><code>Counter({'Adam': 2, 'John': 1})
</code></pre>

<p>I want it to count everything in the list, not just first value of the list. Also, I want my result to be with respect to the key. I will show you my desired output below:</p>

<pre><code>{'a': [{'Adam': 1, 'John': 2}, 'b':{'John': 2, 'Joel': 1}, 'c':{'Adam': 2, 'John': 1 }]}
</code></pre>

<p>Is it possible to get this desired output? Or anything close to it? I would like to welcome any suggestions or ideas that you have. Thank you.</p>

<p>You're picking only the first elements in the each list with <code>values[1]</code>, instead, you want to iterate through each values using a <code>for</code> that follows the first:</p>

<pre><code>&gt;&gt;&gt; from collections import Counter
&gt;&gt;&gt; d = {'a': ['Adam','Adam','John'], 'b': ['John','John','Joel'], 'c': ['Adam','Adam','John']}
&gt;&gt;&gt; Counter([v for values in d.itervalues() for v in values]) # iterate through each value
Counter({'John': 4, 'Adam': 4, 'Joel': 1})
</code></pre>

python list dictionary counter