I've been searching everywhere for a problem that occurred in one of my codes, but didn't see any solution... It's been pretty annoying and that is why I'm asking you this question.
I'm using a simple dictionnary with keys and values, but the problem is when I want to print it at the end it has a strange shuffle where two letters are inverted, like for example "C":"W", "B":"X" instead of "B":"X", "C":"W". Here is my code (it will probably be clearer)
PS. I've first tried in the last few lines to replace the while structure by a for structure, with no improvement.
import random
m1 = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
l1 = ["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
class Separate:
#Used to separate objects in a list
def __init__(self, d):
self.d = d
self.d = "".join(self.d)
l = []
for elt in range(0, len(self.d)):
l.append(self.d[elt])
self.d = l
l1 = Separate(l1)
l1 = l1.d
m1 = Separate(m1)
m1 = m1.d
random.shuffle(m1)
key = {}
count = 0
while count < len(l1):
key[l1[count]] = m1[count]
count+=1
print(key)
This returns (for example) :
{
'A': 'G',
'C': 'A',
'B': 'Z',
'E': 'U',
'D': 'I',
'G': 'W',
'F': 'X',
'I': 'C',
'H': 'K',
'K': 'T',
'J': 'E',
'M': 'F',
'L': 'B',
'O': 'V',
'N': 'D',
'Q': 'M',
'P': 'L',
'S': 'S',
'R': 'J',
'U': 'Q',
'T': 'Y',
'W': 'H',
'V': 'R',
'Y': 'P',
'X': 'N',
'Z': 'O'
}