I have a for loop with an if statement checking if the current character in ‘phrase’ is equal to a character in ‘dictator[column]’ and if it is, it will append the position of a character to a global list ‘listY’ but every time it tries to append the value of ‘column’ to ‘listY’, it overwrites the value that was previously there.
This is the current code for the first part of the code that finds the X and Y of a character in the list ‘encryptionTable’:
def findCypherP1():
a = 0 # length of phrase to encrypt (cypher phrase)
column = 0 # length of encryption section (shuffled alphabet)
row = 0
dictator = encryptionTable[0] # first row of the alphabet
for p in range(len(phrase) * len(dictator)):
global listY
listY = []
if phrase[a] == dictator[column]:
print("Column containing cypher Y:", str(column+1))
column2 = column
listY.append(column2)
a += 1; column = 0
if a >= len(phrase):
print(listY)
break
else:
column += 1
What happens when I run the code is it correctly returns the X value of the characters
Column containing cypher Y: 1
Column containing cypher Y: 11
Column containing cypher Y: 12
Column containing cypher Y: 19
Column containing cypher Y: 3
[2]
But then when it appends ‘column’ to ‘listY’, it overwrites the previous value, I’ve tried making a copy of the int ‘column’ but it only works on lists. If you could help solve this problem, that would be great! Thank you!
Mwolf930 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.