'Transform an expression to a list of terms.'

def as_terms(self):

    from .add import Add
    from .mul import Mul
    from .exprtools import decompose_power
    (gens, terms) = (set([]), [])
    for term in Add.make_args(self):
        (coeff, _term) = term.as_coeff_Mul()
        coeff = complex(coeff)
        (cpart, ncpart) = ({}, [])
        if (_term is not S.One):
            for factor in Mul.make_args(_term):
                if factor.is_number:
                    try:
                        coeff *= complex(factor)
                    except TypeError:
                        pass
                    else:
                        continue
                if factor.is_commutative:
                    (base, exp) = decompose_power(factor)
                    cpart[base] = exp
                    gens.add(base)
                else:
                    ncpart.append(factor)
        coeff = (coeff.real, coeff.imag)
        ncpart = tuple(ncpart)
        terms.append((term, (coeff, cpart, ncpart)))
    gens = sorted(gens, key=default_sort_key)
    (k, indices) = (len(gens), {})
    for (i, g) in enumerate(gens):
        indices[g] = i
    result = []
    for (term, (coeff, cpart, ncpart)) in terms:
        monom = ([0] * k)
        for (base, exp) in cpart.items():
            monom[indices[base]] = exp
        result.append((term, (coeff, tuple(monom), ncpart)))
    return (result, gens)
