Question: Given a list of strings, I need to produce a new string by combining all strings' first character. My solution:

```
def K(lst):
    if lst == []:
        return ""
    else:
        return lst[0][0] + K(lst[1:])

```

It works, but I'm sure that's not accumulative recursion.
I also tried to attempt this question by using accumulative recursion, but I couldn't figure out the correct solution.

```
def K(lst):
    acc = ""
    if lst == []:
        return acc
    else:
        acc = acc + lst[0][0]
        return K(lst[1:])

```

I don't know how to mutate `acc`.

Answer: 
You can't declare your accumulator inside of your recursive function because on each call it will be redefined. You need to make it an argument to your function, a common idiom for this is to create a helper function that has the accumulator in it's definition:

```
def K(lst):
    return _K(lst, [])

def _K(lst, acc):
    if lst == []:
       return acc
    else:
       head, tail = lst[0], lst[1:]
       return _K(tail, acc + head[0])

```
I would not expose the inner function:

```
def K(lst):
    def sub(lst, acc):
        if lst:
            return sub(lst[1:], acc + lst[0][0])
        return acc
    return sub(lst, "")

```

then

```
>>> print K(["abc","bcd","cde"])
abc

```

---

FWIW, there is a way to mimic what you were trying to do, but it is **bad style** and only works in Python 3 because it needs *nonlocal* :

```
def K(lst):
    acc = ""
    def sub(lst):
        if lst:
            nonlocal acc # Python3 only
            acc = acc + lst[0][0]
            return sub(lst[1:])
        return acc
    return sub(lst)

>>> print(K(["abc","bcd","cde"]))
abc

```