s = "k:1|k1:2|k2:3|k3:4" new_li = s.split("|") dic = {} for i in new_li: k,v = i.split(':') dic[k] = int(v) print(dic)
s = "k:1|k1:2|k2:3|k3:4" new_li = s.split("|") dic = {} for i in new_li: k,v = i.split(':') dic[k] = int(v) print(dic)
转载于:https://www.cnblogs.com/Little-Raccoon/p/10818244.html