我正在尝试从txt文件“PortList.txt”创建一个字典,其中的信息格式与下面类似,但不断收到错误“TypeError:unhashable type:'list'”
TCP 0保留
TCP 1端口服务多路复用器
TCP 2管理实用程序
密钥将是“TCP”和“0”,而值是“保留”
我的开场代码是:
portDictionary = {}
with open('PortList.txt', 'r') as infile:
for nextLine in infile:
lineList = nextLine.split()
keys = [lineList[0], lineList[1]]
values = [lineList[2]]
#this won't cover all of the words for the value, but for the test it's just for the first word
portDictionary[keys] = values