How to count values in a list Python 3
<p>I have code like this:</p>

<pre><code>winners = [red, blue, yellow]

player_1_guesses = [red, green, orange]
player_2_guesses = [red, blue, orange]
player_3_guess = [red, green, yellow]
</code></pre>

<p>I'd like to count how many times each value in <code>winners</code> appears across the three <code>player_x_guesses</code> lists. So I would expect to see something like:</p>

<pre><code>totals = {'red': 3, 'blue': 1, 'yellow': 1}
</code></pre>

<p>I'm not really sure what this kind of data analysis (?) is called or even what to google to achieve what I want. </p>

<p>Thanks for any help.</p>

<p>Try doing this:</p>

<pre><code>all_guesses = player_1_guess + player_2_guess + player_3_guess
dct = {i:all_guesses.count(i) for i in winners}
</code></pre>

<p>output:</p>

<pre><code>{'blue': 1, 'yellow': 1, 'red': 3}
</code></pre>

<p>Using <code>collections</code>:</p>

<pre><code>from collections import Counter

dct = Counter(word for word in all_guesses if word in winners)
</code></pre>

python list dictionary counting