3 回答
TA贡献2065条经验 获得超14个赞
for x in hf:
myList1=x.strip().split(',')
dictA[myList1[1]] = myList1[0]
for y in dv:
myList2=y.strip().split(',')
dictB={'Vname':dictA[myList2[0]],'V_Value':myList2[1]}
print(dictB)
这应该给你你需要的东西..但我不知道为什么你需要像这样安排数据
TA贡献1828条经验 获得超4个赞
你可以像下面使用列表理解来做
header_file = '''TotalLoad,M0001001
HoisePosition,X011_0001
TotalLoad1,X011_0004
TotalLoad2,X030_0008
HoisePosition2,X031_0002
GearTemprature,X032_0003
OilLevel,X033_0004
OilTemprature,X034_0005'''
value_file = '''M0001001,50
X011_0001,100
X011_0004,45
X030_0008,35
X030_0002,80
X030_0003,100
X030_0004,200
X030_0005,60'''
hf = [line for line in header_file.split("\n")]
dv = [line for line in value_file.split("\n") ]
header_dict = {key: value for value, key in [line.split(",") for line in hf] }
value_dict = [{"Vname": header_dict.get(key), "V_value": value} for key, value in [line.split(",") for line in dv] ]
print(value_dict)
TA贡献1777条经验 获得超10个赞
for x in hf:
myList1=x.strip().split(',')
dictA[myList1[1]] = myList1[0]
for y in dv:
myList2=y.strip().split(',')
dictB[dictA[myList2[0]] : myList2[1]]
print(dictB)
这是更好的格式
添加回答
举报