I have a dictionary which looks like
a = {32: [2230], 37265: [2218], 51: [2223], 164: [2227], 3944: [2224]}
however, values in a could contain multiple elements, like
a = {32: [2200, 2230], 37265: [2201, 2218], 51: [2223], 164: [2227], 3944: [2224]}
I have a list that stores the keys in a in groups,
b = [[32, 51, 164], [3944, 37265]]
now I want to get values of keys in each group in another list,
clusters = []
for key_group in b:
group = []
for key in key_group:
group.extend(a[key])
if len(group) > 1:
clusters.append(group)
so the final list looks like,
clusters = [[2230, 2223, 2227], [2224, 2218]]
if a contains multiple elements in a value list, clusters looks like,
clusters = [[2200, 2230, 2223, 2227], [2224, 2201, 2218]]
I am wondering what's the best way to do this.
Also in case when b contains list(s) which has only one value/key, and if this key maps to a single element list in a, this list will be ignored,
a = {32: [2200, 2230], 37265: [2201, 2218], 51: [2223], 164: [2227], 3944: [2224]}
b = [[32, 51, 164], [3944], [37265]]
while 3944 maps to [2224], which will be ignored, but 37265 maps to [2201, 2218], which will be kept, since len([2201, 2218]) > 1. clusters will look like the following in this case,
clusters = [[2200, 2230, 2223, 2227], [2201, 2218]]