Question: I would like to know how to do an equivalent of the range function in python, but with the ability to specify the base number. For example:

```
countUp(start=0, end=1010, base=2)
countUp(start=0, end=101, base=3)
countUp(start=0, end=22, base=4)

```

Example output for base 2 counting:

```
[0, 1, 10, 11, 100, ...]

```

Is there a function I'm missing that does this? Or what could I do instead?

Answer: 
You can do it with a custom iterator:

I took the iterater code from [here](https://stackoverflow.com/a/24377/4194964) and the base conversion from [here](https://stackoverflow.com/a/2267446/4194964)

```
import string
class BaseRange:
    def __init__(self, low, high, base):
        digs = string.digits + string.letters
        self.current = low
        self.high = high
        self.base = base
    def __iter__(self):
        return self
    def next(self):  # Python 3 requires this to be __next__
        if self.current > self.high:
            raise StopIteration
        else:
            self.current += 1
            return self.int2base(self.current - 1, self.base)
    def int2base(self, x, base):
        if x < 0: sign = -1
        elif x == 0: return digs[0]
        else: sign = 1
        x *= sign
        digits = []
        while x:
            digits.append(digs[x % base])
            x /= base
        if sign < 0:
            digits.append('-')
            digits.reverse()
        return ''.join(digits)

```

A Few Example runs produces:

```
>>> for c in BaseRange(0, 10, 2):
    print(c)

0
1
01
11
001
101
011
111
0001
1001
0101
>>> for c in BaseRange(0, 10, 3):
    print(c)

0
1
2
01
11
21
02
12
22
001
101

```
You could do this with the itertools [product](https://docs.python.org/3/library/itertools.html#itertools.product) function.

```py
from itertools import product

def countUp(start, end, base):
    n_digits = len(end)
    combs = product(*[range(base)] * n_digits)
    while (n := next(combs)) <= end:
        yield n

list(countUp(start=0, end=(2, 0), base=3))
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)]

```