用python,正则或其他方法,分割字符串
用python,正则或其他方法,分割字符串?
1
2
3
4
5
6
7
8
9
a="""cellId =0xd, ueId = 0xd0000, ueIndex = 0x0, crnti = 0x54e5
trId=6815744 ueId=851968 crnti=21733 hoType=0 numOfSrb=1 numOfDrb=0 poolId=0
cellId =0xd, ueId = 0xd0002, ueIndex = 0x10, crnti = 0x5567"""
#先格式处理,将=,换行符和 统一使用逗号分隔
a=a.replace(" ",",").replace("=", ",").replace("\n",",")
#过滤无效的值
b = filter(None,a.split(","))
#转换成字典
d = dict(zip(b[0::2], b[1::2]))
d就是你要的字典,不过你这给出的可是有重复的键呢,比如ueId,它就是重复的,重复的取最后一次覆盖的值,