1、python 正則匹配一串字符串內容中的正數或負數

import re pattern = re.compile(r'-\d+|\d+') # 用於匹配正值或負值 values = pattern.findall('\r\nNUESTATS:CELL,3684,164,1,-936,-109,-849,98\r\n\r\nOK\r\n') print(values)
2、python zip函數將兩個列表合並成字典

import re pattern = re.compile(r'-\d+|\d+') # 用於匹配正值或負值 values = pattern.findall('\r\nNUESTATS:CELL,3684,164,1,-936,-109,-849,98\r\n\r\nOK\r\n') 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)