futui 发表于 2023-5-4 10:18:40

请大师帮做个字典,谢谢

请大师帮做个字典,谢谢

1:300395/菲利华/9.38%/536.81/29,524.39。;2:300593/新雷能/8.82%/653.62/27,765.83。;10:603105/芯能科技/2.51%/535.72/7,891.21。


怎么把上面做成如下字典:键是冒号和斜杠之间的6位数,值是第二个斜杠后的值
{‘300395’:9.38,‘300593’:8.82,‘603105’:2.51}

wp231957 发表于 2023-5-4 10:32:40

s="1:300395/菲利华/9.38%/536.81/29,524.39。;2:300593/新雷能/8.82%/653.62/27,765.83。;10:603105/芯能科技/2.51%/535.72/7,891.21"
dic={}
for x in s.split(";"):
    m=x.split("/")
    dic.split(":")]=m[:-1]
print(dic)   

wp231957 发表于 2023-5-4 10:33:01

D:\wpp>D:/Python37/python.exe d:/wpp/test10.py
{'300395': '9.38', '300593': '8.82', '603105': '2.51'}
页: [1]
查看完整版本: 请大师帮做个字典,谢谢