展开全部
代码如下:62616964757a686964616fe4b893e5b19e31333363376466keys = ['PID', 'USERNAME', 'THR', 'PRI', 'NICE', 'SIZE', 'RES', 'STATE', 'TIME', 'WCPU', 'COMMAND']
items = ['32', 'root', '1', '-36', '-155', '0K', '16K', 'WAIT', '0:00', '0.00%', 'swi3:', 'ip6opt', 'ipopt']
dt = dict()
keys_len = len(keys)
items_len = len(items)
# 先读取除最后一个key写入字典
for i in range(keys_len-1):
dt[keys[i]] = items[i]
# 读取最后一个key和值写入字典
command_key = keys[i]
command_text = []
for i in range(keys_len-1,items_len):
command_text.append(items[i])
dt[command_key] = ' '.join(command_text)
# 输入字典结果
print(dt)
输出如下:{'NICE': '-155',
'PID': '32',
'PRI': '-36',
'RES': '16K',
'SIZE': '0K',
'STATE': 'WAIT',
'THR': '1',
'TIME': '0:00',
'USERNAME': 'root',
'WCPU': 'swi3: ip6opt ipopt'}