python - appending dictionary to master list -
For some reason it is not allowing me to add a string item to a key in a dictionary
This is my code:
Example Code: Why is not it working? splitUserList (line) :
gt; & Gt; & Gt;
def createUserList (): userList = [] Total User List = [] F = Open ("u.user.txt") For user, userDict = {} single user list = spit user list (line) userdict ["age"] = single user list [1] userdict ["gender"] = single user list [2] userdict ["business" ] = Single user list [3] single user ["zip"] = single user list [4] userList.append (userDict) returns userList
Traceback (most recent call final): file "/ applications / wingideapp / content / macus / src / debug / teas / server / _ sandbox", line 1, & lt; Module & gt; # Error file in the "File / Applications / WingIDAP / Content / MacS / SRC / debug / post / server / _ sandbox_jap", line 20, internally used for debug sandbox under external interpreter file: List index I should be assuming that
userDict ["zip"] = single user list [4]
single user list ["zip"] = single Ughr list [4] # & lt; - Single user list list, # and you can not index it through string
Comments
Post a Comment