Solution: Python loop using “_”

Development | Programming languages
Author
Description

I have written a few python script. But this is my first time of seeing expressions like "for _ in range(100000)". Can anyone point me a direction regarding this? I didn't find it from google. What does "_" mean? no parameter is needed, and we can use this merely to say loop for 100000 times?


from numpy import random
random.seed(0)

totals = {20:0, 30:0, 40:0, 50:0, 60:0, 70:0}
purchases = {20:0, 30:0, 40:0, 50:0, 60:0, 70:0}
totalPurchases = 0
for _ in range(100000):
    ageDecade = random.choice([20, 30, 40, 50, 60, 70])
    purchaseProbability = float(ageDecade) / 100.0
    totals[ageDecade] += 1
    if (random.random() < purchaseProbability):
        totalPurchases += 1
        purchases[ageDecade] += 1
Attachments
No attachments.
Solutions
It's just an identifier, by convention used to indicate that the variable is unused
on September 05th, 2018 (9:18 pm)
What masters said
You must sign in to comment!!
All comments
This solution has not been commented yet.