mercredi 9 septembre 2020

How come when i print new dict, my Trial 1 and Trial 2 value are the same even though i already randomised for all the name

Dict = , {Trial:2, {John:4, Harry: 3, Dick: 2}}}
NewDict = {}
for Trial, TValue in Dict.items(): 
 for Name, Value in TValue.items():
  TValue[Name] = random.random()
  NewDict[Trial]= TValue

print(NewDict) 

#My output will be something like else this:

Dict = , {Trial:2, {John:3, Harry: 4, Dick: 5}}}

#What I want is all my values in the dictionary are different.

#Eg.

Dict = , {Trial:2, {John:7, Harry: 2, Dick: 3}}}



Aucun commentaire:

Enregistrer un commentaire