Skip to content
Advertisement

dictionary update – very strange behaviour

When running below code, the dict shows unexpected behaviour

I a nutshell, I select a date in the past and add the information to a dict about that date. All is well until I print the resulting dict after all the iterations:

functioning code, you can C/V this into your shell and run it with dictTester():

JavaScript

python shell output

JavaScript

So you would expect the result dict to be:

JavaScript

But instead it prints:

JavaScript

and you can see more of this funky behaviour when increasing the row value

for 3 you should get a ‘PURE’ a ‘LEFT’-‘RIGHT’ and a ‘LEFT’-‘MIDDLE’-‘RIGHT’ and so on, you get the idea

but that would be disregarding the adversary.

Advertisement

Answer

The simple bug was a pass by reference vs pass by value error, silly me

as answered here: python list by value not by reference

updating the code line:

JavaScript

to

JavaScript

was all that was required

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement