Ask coding questions

← Back to all posts
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.

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.

Answered by pyelias (1481) [earned 5 cycles]
View Answer
cv88 (0)
pyelias (1481)

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.