Problem with lists
Chris Angelico
rosuav at gmail.com
Tue Sep 15 20:46:48 EDT 2015
On Wed, Sep 16, 2015 at 10:29 AM, Rafael David <rdavid.br at gmail.com> wrote:
> Oooohhh ... I think I got it! I'm assigning a reference to peca and not the value itself! Thank you very much MRAB and C Smith for the enlightenment :)
Right! That's how Python's assignment always works. You may find, in
your case, that you can simply reassign peca={} every time through the
loop. No copying necessary - just make yourself a new dict for each
iteration.
And you might be able to do the whole thing with a gigantic
list/list/dict comprehension, but that may or may not be an
improvement on your code :)
ChrisA
More information about the Python-list
mailing list