I’m working in python and currently have the following code:
list = []
for a in range(100):
for b in range(100):
for c in range(100):
list.append(run(a,b,c))
where run(a,b,c) returns an integer (for example, it could multiply the three numbers together). Is there a faster way to either loop over these numbers or use a map function?
Thanks 🙂
Have a look at the itertools-module and particulary the product method
example usage:
Note that the function call can be shortened to:
in the example above. see docs.python.org for explanation of Unpacking Argument Lists.
As an example, the output from
product(range(0,2), repeat=3))looks like this: