import random
import itertools

def test(number):
	return random.random()*number

Say I have a function and I want to repeat it x times so that I may calculate the standard deviation. How can I do this? I've tried using itertools.repeat(test(5),3) but it prints repeat(value,3) which I can't calculate the standard deviation. I feel like I am missing something really simple....
Any thoughts?
Thanks a bunch!

Recommended Answers

All 2 Replies

Write a loop

for i in range(3):
    print test(5)

Or if you want to create a list of numbers

the_list = [ test(5) for i in range(3) ]

Also generator for loop would not be so bad as OP is considering itertools:

import random
def test(number):
    for count in range(number):
        yield random.random()

the_list = list(test(5))
print the_list
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.