我有幾個名單如下:構建詞典列表從幾個名單在Python
Pargs = [args.Pee, args.Pem,...,args.Pet] # 9 elements of boolean type
indices = [(0,0),(0,1),...,(2,2)] # 9 possible combinations (i,j), i = 0,1,2; j = 0,1,2
D = [{},{},...,{}] # 9 dictionaries, desired result
我希望看到應該是這樣的結果:
D = [{event:args.Pee,i:0,j:0},{event:args.Pem,i:0,j:1},...{event: args.Pet,i:2,j:2}]
字典必須按照上圖所示進行訂購。
我試圖
for d in D:
for i in range(3):
for j in range(3):
d['i'],d['j'] = i,j
但它不會做的伎倆。我已經嘗試過許多使用zip(),product(),dict()的算法,但無濟於事...
你只是結合了'Pargs [0]'和'indices [0]','Pargs [1]'和'indices [1]'等等嗎? – glibdud
@glibdud就我所知,是的。 – Albert
是否必須下訂單? – SirParselot