Counting frequencies in two lists, Python
<p>I'm new to programming in python so please bear over with my newbie question...</p>

<p>I have one initial list (list1) , which I have cleaned for duplicates and ended up with a list with only one of each value (list2): </p>

<p>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16],</p>

<p>list2 = [13, 19, 2, 16, 6, 5, 20, 21]</p>

<p>What I want is to count how many times each of the values in "list2" appears in "list1", but I can't figure out how to do that without getting it wrong. </p>

<p>The output I am looking for is something similar to this: </p>

<p>Number 13 is represented 1 times in list1. 
........ Number 16 is represented 2 times in list1. </p>

<p><strong>Simplest</strong>, <strong>easiest</strong> to understand, <strong>no-magic-approach</strong> is to create an object(associative array) and just count the numbers in list1:</p>

<pre><code>list1 = [13, 19, 13, 2, 16, 6, 5, 19, 20, 21, 20, 13, 19, 13, 16]

frequency_list = {}

for l in list1:
    if l in frequency_list:
        frequency_list[l] += 1
    else:
        frequency_list[l] = 1

print(frequency_list)
</code></pre>

<p>prints out this:</p>

<pre><code>{
    16: 2,
    2: 1,
    19: 3,
    20: 2,
    5: 1,
    6: 1,
    13: 4,
    21: 1
}
</code></pre>

<p>meaning 16 is there twice, 2 is there once...</p>

python list frequency counting