-2

Playing around with some number theory problems. I would like a way to loop (n-times) over all the digits from 0 to 9, given n.

Assuming an easier way is to first generate all the tuples and loop over them once, what is the quickest way (in Python) to generate all n-tuples with elements the digits from 0 to 9? E.g. for n=2, (0,0), (0,1), (0,2)...(9,8),(9,9).

1 Answers1

3
import itertools

def func(n):
    for v in itertools.product(range(10),repeat=n):
        print(v)
func(2)
islam abdelmoumen
  • 662
  • 1
  • 3
  • 9