mardi 25 avril 2017

How can I create a dictionary in python that has random letters as keys with no duplicates?

This is my code:

I create some random letters and I store them in variables, then I use this variables as keys in the dictionary. The problem is that the keys are duplicates because of the random letters. How can I fix that?

a = random.choice(string.ascii_letters).lower()
b = random.choice(string.ascii_letters).lower()
            .
            .
            .
z = random.choice(string.ascii_letters).lower()

alphabet = 
{'a':a,'b':b,'c':c,'d':d,'e':e,'f':f,'g':g,'h':h,
'i':i,'j':j,'k':k,'l':l,'m':m,'n':n,
'o':o,'p':p,'q':q,'r':r,'s':s,'t':t,
'u':u,'v':v,'w':w,'x':x,'y':y,'z':z} 




Aucun commentaire:

Enregistrer un commentaire