You can add the logic here too, if you want. Something like

(add to the top of the function)

```py
addterms = 1
```

(then replace the above `else`)

```py
elif a.is_Add:
   addterms *= a 
else:
    other.append(a)
```

Then at the end of the loop, do something like

```py
addtermsre, addtermsim = expand_mul(addterms, deep=False).as_real_imag()
```

But then at the very end, you need to incorporate this into the result.  This way would be more efficient because it would only expand the Add arguments of the Mul, so for instance if you have `x*(1 + I)*(1 + 2*I)` it would only expand `(1 + I)*(1 + 2*I)`.

Make sense?