I am trying to create a co-occurrence matrix from a dictionary of unique keys with overlapping values (in Python 3). Here is my data structure:
keys = ['A','B','C','D']
vals = [[1,2],1,[1,3],2]
dict = {'A':[1,2], 'B':1, 'C':[1,3], 'D':2]}
How can I create matrix that counts the occurrences of the values for each key in the form:?
1. 2. 3.
A. 1 1 0
B. 1 0 0
C. 1 0 1
D. 0 1 0
I've been recommended to use defaultdict
but I am not sure how to implement it.
Thank you!