Very odd functionality in list (python)
cv88 (0)

I am currently writing the following code, which is designed to decipher autokey algorithms given a certain keylength.

https://repl.it/@cv88/Autokey-algorithm

Yet I have run into a strange and entirely unexpected problem, in an area that I wouldn't expect it to appear. Put simply, line 36 seems to be the problem, and line 35 and line 37 are debugging lines to prove this. Basically, something is added to the (global) list 'key' on that line, without the list being mentioned, or even it being part of the decrypt() function. I don't think a full explanation of the entire program is necessary here but I can give one if you ask for it.

You are viewing a single comment. View All
pyelias (930)

When you do line = key, line and key become the same list, so changing one will also change the other. You can use line = key[:] or line = list(key) to copy key and fix the problem.

cv88 (0)

@pyelias thankyou, this seems to have fixed the problem.