What is it:
This is a simple function, part of a basic Monte Carlo simulation. It takes the size of the sample and the probability as parameters. It returns the result of the simulation (positive responses) plus the input parameters in a tuple.
What I ask:
I try to avoid using temporary variables, I have two questions.
- Am I really saving memory by avoiding storing intermediate results?
- How can I improve readability without adding variables?
def simulate_survey (sample_size, percent_subscribes): return ( sample size, pourcentage_souscrit, round( ( sum([ r.random() < percent_subscribes for _ in range(sample_size) ]) / size of the sample ) 2 ) )
Thank you for your opinion.