I would like, from a pair of lists, say:
a = ['str1', 'str2', 'str3', 'str4', 'str5']
b = [var1, var2, var3, var4, var5]
to be able to create multiple dictionaries, with arbitrarily selected pairs of elements from a (as keyword) and b (as value). I have found in a comment on an answer to this question, the following method:
full_set = dict(zip(a,b))
subset = {i:full_set[i] for i in a if i not in ['str2', 'str5']}
which produces subset dictionary:
{'str1': var1, 'str3': var3, 'str4': var4}
This works fine, but I am curious as to whether there is an equally short or shorter method of building subset dictionaries from the two lists, e.g. via specifying the list indices for the elements I want included, without creating a full dictionary containing all elements first.
For context, my vars refer to scikit-learn estimator objects.