1、python 正则匹配一串字符串内容中的正数或负数
import re pattern = re.compile(r'-d+|d+') # 用于匹配正值或负值 values = pattern.findall(' NUESTATS:CELL,3684,164,1,-936,-109,-849,98 OK ') print(values)
2、python zip函数将两个列表合并成字典
import re pattern = re.compile(r'-d+|d+') # 用于匹配正值或负值 values = pattern.findall(' NUESTATS:CELL,3684,164,1,-936,-109,-849,98 OK ') print(values) #values 运行的结果:['3684', '164', '1', '-936', '-109', '-849', '98'] keys = ['earfcn','physical cell id','primary cell','rsrp','rsrq','rssi','snr'] dictionary = dict(zip(keys, values)) # 把两个列表合并成一个字典 print(dictionary)