Combining And Associating Multiple Dictionaries
I want to generate a dictionary in which six different combination of three different groups of pictures are organized. Thats why I computed a dictionary: import glob, os, random,
Solution 1:
To answer the first point, you can use itertools.permutations
:
import itertools as it
elements = [im_a, im_n, im_e]
perms = it.permutations(elements, 2) # 2 -> take pairs
pic_list = [sum(perm, []) for perm in perms]
The order returned is lexicographic, i.e.
im_a + im_n, im_a + im_e, im_n + im_a, im_n + im_e, im_e + im_a, im_e + im_n
The respective cond_list
can be built by simply doing:
cond_list = [im_a] * 2 + [im_n] * 2 + [im_e] * 2
Or, more generally:
d = len(elements) - 1cond_list = list(chain.from_iterable([el]*d for el in elements))
# orcond_list = sum(([el]*d for el in elements), [])
Post a Comment for "Combining And Associating Multiple Dictionaries"