python - Combining all combinations of two lists into a dict of special form -


i have 2 lists:

var_a = [1,2,3,4]  var_b = [6,7] 

i want have list of dicts follows:

result = [{'a':1,'b':6},{'a':1,'b':7},{'a':2,'b':6},{'a':2,'b':7},....] 

i think result should clear.

from itertools import product  = [1,2,3,4] b = [6,7] [dict(zip(('a','b'), (i,j))) i,j in product(a,b)] 

yields

[{'a': 1, 'b': 6},  {'a': 1, 'b': 7},  {'a': 2, 'b': 6},  {'a': 2, 'b': 7},  {'a': 3, 'b': 6},  {'a': 3, 'b': 7},  {'a': 4, 'b': 6},  {'a': 4, 'b': 7}] 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -