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>In technical terms, <code>list</code> is a "type" of "object". Python has a number of built in types like strings (<code>str</code>), integers (<code>int</code>), and a few others that can be easily found on google. The reason this is important is because each object type has its own "methods". You can think of these methods as functions that complete common programming tasks and make your life easier. </p>

<p>Counting the number of occurrences in a list is an example of a common programing task. We can accomplish it with the <code>count()</code> method. For example, to count the number of times 13 appears in list1: </p>

<pre><code>count_13 = list1.count(13)
</code></pre>

<p>We can also use a for loop to iterate over the whole list:</p>

<pre><code>for x in list2:
    print(list1.count(x)) #This is for python version 3 and up
</code></pre>

<p>or for python versions older than 3:</p>

<pre><code>for x in list2:
    print list1.count(x) #This is for python version 3 and up
</code></pre>

python list frequency counting