I have the following code inside a while loop.
if gender == 0 and len(men) < 51 :
height = float((random.uniform(1.3, 1.9) + (random.randint(10, 20)/100.)).__format__('.2f'))
weight = float((random.uniform(45, 100) * height).__format__('.2f'))
attr['height'] = height
attr['weight'] = weight
men.append(attr)
So this code always gives some random height and random weight. But outsite de loop (when it is finished). If I do print men
, I get the following result:
[{'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}, {'weight': 76.64, 'height': 1.75}]
Its always the same thing. But, if I instead of using attr[height] = height; attr['weight] = weight
and use men.append(height); men.append(weight)
I get the following result:
print men
[1.91, 145.95, 1.64, 95.66, 2.0, 159.94, 1.74, 143.36, 1.68, 97.99, 1.6, 90.11, 1.63, 116.2, 1.56, 96.8, 2.04, 198.56, 1.56, 145.96, 1.44, 67.57, 1.83, 94.97, 1.85, 175.69, 1.84, 101.84, 1.54, 135.0, 1.41, 101.23, 1.92, 167.59, 1.74, 142.55, 1.49, 129.07, 1.83, 161.28, 1.59, 97.16, 1.46, 134.53, 2.03, 158.72, 2.05, 184.43, 1.97, 162.81]
If I print attr inside the loop it always has a different value ( its what I want). But when I append it to my list, the values of my list are always the same. What am I doing wrong?
attr = {'height': height, 'weight': weight}
ormen.append(attr.copy())