Question: I just made a function to generate a list of running ids between a given range. IDs begin with an alphabet and follow with 5 numbers (e.g. A00002). The function below works, but I was wondering if there was a cleaner way to do this. Thanks!

```
def running_ids(start, end):
list = []
start = int(start[1:])
end = int(end[1:])
steps = end - start

def zeros(n):
    zeros = 5 - len(str(n))
    return zeros

while start <= end:
    string = "A" + "0"*zeros(start) + str(start)
    list.append(string)
    start += 1

return list

```

print running\_ids('A00001', 'A00005')

> 
> 
> > 
> > 
> > > 
> > > ['A00001', 'A00002', 'A00003', 'A00004', 'A00005']
> > > 
> > > 
> > > 
> > 
> > 
> > 
> 
> 
>

Answer: 
Use a [generator](https://wiki.python.org/moin/Generators). This way you can generate the numbers as needed and not store them all at once. It also maintains the *state* of your counter, useful if you start building large projects and you forget to add one to your index. It's a very powerful way of programming in Python:

```
def running_id():
    n = 1
    while True:
        yield 'A{0:05d}'.format(n)
        n += 1

C = running_id()
for n in xrange(5):
    print next(C)

```

Giving:

```
A00001
A00002
A00003
A00004
A00005

```
You can use the builtin [`format`](http://docs.python.org/2/library/functions.html#format) method

```
print "A" + format(1, "05d")   # A00001
print "A" + format(100, "05d") # A00100

```

Or you can use [`str.zfill`](http://docs.python.org/2/library/stdtypes.html#str.zfill) method like this

```
print "A" + str(1).zfill(5)    # A00001
print "A" + str(100).zfill(5)  # A00100

```