Q:

python: How to count the frequency of given elements in a list

I understand the counter function counts the frequency of every element in a list. But I would like it to include the frequency from given elements even the element doesn't appear in the list.
for example:
A list of expected elements are given as: 
expected_element = [1,2,3,4,5,6,7]

for the datasets a,b:
a = [1,1,1,1,6,6,6,3,3,4,5,5]
b = [2,2,7,1,7,5,3,5,5]

and what I want is to count frequency of expected_element in a and b:
for a:
keys() =   [1,2,3,4,5,6,7]
values() = [4,0,2,1,2,3,0]

for b:
keys() =   [1,2,3,4,5,6,7]
values() = [1,2,1,0,3,0,2]    

A:

You can create a dictionary with the unique keys in set(a), paired with null values, then update it with Counter(b):
from collections import Counter

a = [1,1,1,1,6,6,6,3,3,4,5,5]
b = [2,2,7,1,7,5,3,5,5]

frequencies = {key: 0 for key in set(a)}
frequencies.update(Counter(b))
print(frequencies)

output:
{1: 1, 3: 1, 4: 0, 5: 3, 6: 0, 2: 2, 7: 2}

