So i am simply trying to append my list containing a set of numbers, to a value in a dictionary which is currently a list.
I don't know whether it is important but some of the lists in the dictionary are empty and some contain integers.
I assumed this would be simple and tried the most obvious thing to me which was appending the list to that value like this.
middlenumberdic[y].append(numberlist)
However this gave me the following error:
middlenumberdic[y].append(numberlist)
KeyError: 786
So i decided that the problem was that lists couldn't apppend with lists so i broke it up into individual integers
for value in numberlist:
middlenumberdic[y].append(value)
but this just gave me the same KeyError thing
middlenumberdic[y].append(value)
KeyError: 792
From my point of view i would've thought that middlenumberdic[y]
would return [123,456,789]
(as that is what is assigned to it) and then that i could just append to that list but apparently i can't.
Before doing all this i tried middlenumberdic[y] = numberlist
and although this didn't result in an error all it did was overwrite my existing list rather than adding to it.
After reading How to append to a list in a dictionary? and Append to a list within a dictionary i was still none the wiser which is why i have posted this.
For the first question the answer given was much the same as the solution i used which didn't work and the other question was to complicated for me to understand.
This is my first question i've asked on this site so i'm sorry if i've done something wrong.
P.S Their is more script but i thought only this would be neccesary