### recurrence relation

I have the following recurrence ~~relation, ~~relation (which gives the cycle index of the symmetric group), where $a_k$ are just indeterminates:

$Z_0 := 1, \quad Z_n := \frac1n \sum_{k=1}^n a_k Z_{n-k} \quad \forall n>0$

I tried the following, but it doesn't work:

```
def Z(n):
if n == 0:
return 1
else:
a = var(','.join('a%s'%(i+1) for i in range(n)))
return 1/n*sum(a[k-1]*Z(n-k),k,1,n)
```

What am I doing wrong?

**Edit**: Based on dan_fulea's answer, I found a way how to put `a`

inside `Z(n)`

:

```
def Z(n):
if n == 0:
return 1
a = var(','.join(f'a{k}' for k in [0..n]))
return 1/n * sum([ a[k] * Z(n-k) for k in [1..n] ]).expand()
```