Python 将字典追加到主列表

Python 将字典追加到主列表,python,file-io,dictionary,Python,File Io,Dictionary,出于某种原因,它不允许我向字典中的键添加字符串项 这是我的密码: splitUserListline的示例: 代码: 为什么它不起作用 Traceback (most recent call last): File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 1, in <module> # Used internally for debug sandbox

出于某种原因,它不允许我向字典中的键添加字符串项

这是我的密码:

splitUserListline的示例:

代码:

为什么它不起作用

Traceback (most recent call last):
  File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 1, in <module>
    # Used internally for debug sandbox under external interpreter
  File "/Applications/WingIDE.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 20, in createUserList    
TypeError: list indices must be integers, not str
我猜你的意思是

userDict["zip"] = singleUserList[4]
而不是

singleUserList["zip"] = singleUserList[4]  # <-- singleUserList is a list, 
                                           #     and you cannot index it via a string
我猜你的意思是

userDict["zip"] = singleUserList[4]
而不是

singleUserList["zip"] = singleUserList[4]  # <-- singleUserList is a list, 
                                           #     and you cannot index it via a string