w***w 发帖数: 362 | 1 有
A=[a1, a2, a3]
B=[b1, b2, b3]
C=[c1, c2, c3]
怎么生成:
[{'A':a1, 'BC':{'B':b1,'C': c1}},
{'A':a2, 'BC':{'B':b2,'C': c2}},
{'A':a3, 'BC':{'B':b3,'C': c3}}]
多谢啦! | a*****a 发帖数: 46 | 2 import pprint
A = ['a1', 'a2', 'a3']
B = ['b1', 'b2', 'b3']
C = ['c1', 'c2', 'c3']
res = []
for i in range(3):
l1 = {}
l1['A'] = A[i]
l1['BC'] = {}
l1['BC']['B'] = B[i]
l1['BC']['C'] = C[i]
res.append(l1)
pprint.pprint(res)
不知道理解的对不对,觉得说的有点模糊
【在 w***w 的大作中提到】 : 有 : A=[a1, a2, a3] : B=[b1, b2, b3] : C=[c1, c2, c3] : 怎么生成: : [{'A':a1, 'BC':{'B':b1,'C': c1}}, : {'A':a2, 'BC':{'B':b2,'C': c2}}, : {'A':a3, 'BC':{'B':b3,'C': c3}}] : 多谢啦!
| w***w 发帖数: 362 | 3
对的
【在 a*****a 的大作中提到】 : import pprint : A = ['a1', 'a2', 'a3'] : B = ['b1', 'b2', 'b3'] : C = ['c1', 'c2', 'c3'] : res = [] : for i in range(3): : l1 = {} : l1['A'] = A[i] : l1['BC'] = {} : l1['BC']['B'] = B[i]
|
|