1. 程式人生 > >Python3.6全棧開發實例[010]

Python3.6全棧開發實例[010]

字符串 字符 clas pan code pre pri 3.6 開發實例

10.有字符串 "k:1|k1:2|k2:3|k3:4" 處理成字典 {‘k‘:1,‘k1‘:2....}

s = "k:1|k1:2|k2:3|k3:4"
dic = {}
l1 = s.split(|)
for i in l1:
  k,v = i.split(:)
  dic[k] = v
  print(dic)

Python3.6全棧開發實例[010]