I'm having trouble comparing a nested list with a dictionary of multiple values. The dictionary and nested list are like so:
list = [[['a']], [['b']], [['c'], ['d']], [['e'], ['f'], ['g']]]
dict = {'adv0' : ('a', 'b'), 'adv1' : ('f', 'c'), 'adv2' : ('d', 'e', 'q')}
I want to create an array where each sublist ('a', 'b', 'c & d', 'e & f & g') is compared to each value and if any item in the sublist is a member of that value it creates a 0 entry, otherwise it creates a 1 entry.
[0, 1, 1] since 'a' is only in adv0, [0, 1, 1] since 'b' is only in adv0, [1, 0, 0] since adv1 and adv2 contain 'c' or 'd', [1, 0, 0] since adv1 and adv2 contain one of 'e', 'f' or 'g'. Hence we get the array [0,1,1,0,1,1,1,0,0,1,0,0].
The following code is my horrible attempt at a solution which doesn't work:
l = []
for sublist in list:
for items in sublist:
for x in items:
for key in dict:
if x in dict[key]:
l.extend('0')
elif x not in dict[key]:
l.extend('1')
print l