The picture is the best way to explain my problem, but I'm trying to populate a dictionary object in python, such that each key in the dictionary has a value of a list. Currently, all keys point to the same list. This is not what I want. Instead, I want each key to be associated with an independent copy of that list. I don't want to change the list in dict[1] and have that change also occur in dict[2].
If there is a better object for this kind of task that a dict, I would love to hear that advise as well.
I tried using a list (of lists), but this gave me the same error (which surprised me).
Thanks! A bit of a noob! Sorry!
This is some code that might be helpful:
samples={} for x in range (1,653): samples[x]=list
so, I want the same list to be the value of every key in the dictionary, but when I type
sample[3].append('Hello'), I don't want sample[4] to also contain the appended 'Hello'.
To clarify, my keys are integers. It's the values that they're pointing to (a list, specifically) that I'm having a problem with.
cross-posted on stats.stackexchange.com: http://stats.stackexchange.com/questions/16629