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>Not sure if I'm breaking the rules here, but my approach was to search for
"python compare string arrays" and I got this: <a href="http://stackoverflow.com/questions/2783969/compare-string-with-all-values-in-array">Compare string with all values in array</a></p>

<p>You have one list/array of strings that you want to compare with three other lists/arrays.</p>

<p>Assuming you want to know how many players guessed the correct colour and in the right position.  In other words player_1_guesses = [green, red, orange] would not count as a correct guess for red because it's not in the first position, for your example.</p>

<p>In my head, the logic of your code would go like this (this isn't python code by the way!):</p>

<ol>
<li>get winners[0], which is 'red'</li>
<li><p>check winners[0] against values in player_n_guesses[0] and record the outcome in a variable called red (e.g. if player_n_guesses[0]==winners[0]:red +=1)</p></li>
<li><p>use nested for loops to go through everything, then make your totals list using the format method.</p></li>
</ol>

<p>I expect there's a more efficient way that directly compares matrices - try searching for 'string matrix comparison python' or something like that.</p>

python list dictionary counting