List vs generator comprehension speed with join function

So I got these examples from the official documentation. https://docs.python.org/2/library/timeit.html What exactly makes the first example (generator expression) slower than the second (list comprehension)? >>> timeit.timeit('"-".join(str(n) for n in range(100))', number=10000) 0.8187260627746582 >>> timeit.timeit('"-".join([str(n) for n in range(100)])', number=10000) 0.7288308143615723 Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the … Read more

List on python appending always the same value

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 … Read more