用 Python 语言将字符串:"k:1|k1:2|k2:3|k3:4",处理成 python 字典:{k:1, k1:2, ... }

cc = "k:1|k1:2|k2:3|k3:4"
def cy(cs):
    dict1 = {
     }
    for kv in cs.split("|"):
        k,v = kv.split(":")
        dict1[k] = v
    return dict1

a = cy(cc)
print(a)

你可能感兴趣的:(python题库)