Oct-08-2019, 01:14 PM
My code below works. I used a second variable (count) to generate the dictionary. How could I have done this more efficiently?
import random str = "abcdefg" print() print(' This program randomly generates a cipher dictionary from the string',str,end="") print('.') print(' Cipher dictionary is:') def make_cipher_dict(str): CIPHER_DICT = {} lst = list(str) sndlst = list(str) random.shuffle(sndlst) #random method changes specified list rather than creating new list # print(lst) DEBUG # print(sndlst) DEBUG # quit() DEBUG count = 0 for a in lst: CIPHER_DICT[a] = sndlst[count] count = count + 1 print("",CIPHER_DICT) return; make_cipher_dict(str)