2 回答
TA贡献1946条经验 获得超3个赞
您可以尝试使用字典:
L = [
["ImoduleB.pinN_in", "ImoduleC.pinO_out"],
["ImoduleA.pinM_in", "ImoduleB.pinN_out"],
["ImoduleC.pinO_in", "ImoduleD.pinP_out"]
]
k = []
for i in L:
d = {}
for j in i:
s = j.split(".")
d.update({s[0]:s[1]})
k.append(d)
print(k)
输出 :
[{'ImoduleB': 'pinN_in', 'ImoduleC': 'pinO_out'},
{'ImoduleA': 'pinM_in', 'ImoduleB': 'pinN_out'},
{'ImoduleC': 'pinO_in', 'ImoduleD': 'pinP_out'}]
TA贡献2019条经验 获得超9个赞
L = [
["ImoduleB.pinN_in", "ImoduleC.pinO_out"],
["ImoduleA.pinM_in", "ImoduleB.pinN_out"],
["ImoduleC.pinO_in", "ImoduleD.pinP_out"]
]
# split every item
L_instances = [[i.split('.')[0] for i in x ]for x in L]
# [['ImoduleB', 'ImoduleC'], ['ImoduleA', 'ImoduleB'], ['ImoduleC', 'ImoduleD']]
L_pins= [[i.split('.')[1] for i in x ]for x in L]
# [['pinN_in', 'pinO_out'], ['pinM_in', 'pinN_out'], ['pinO_in', 'pinP_out']]
添加回答
举报