Python string processing based on the numeric part: '5a+6b' + '2a+3b+9c' = '7a+9b+9c'
<p>I need to add two simple polynomials (represented as strings). The following example would clarify my requirement.</p>

<pre><code>input1 = '5a+6b'
input2 = '2a+3b+9c'
</code></pre>

<p>The required sum should be as follows:</p>

<pre><code> '7a+9b+9c'
</code></pre>

<p>Currently I have created a function (of 20 lines) to perform this task for me, but I think this can be improved.</p>

<p>EDIT: Adding my code</p>

<pre><code>def add_domain_strings():
    input_list = ['5a+6b', '2a+3b+9c']
    vars_dict = {}
    for input in input_list:
        temp_list = input.split('+')
        for i in temp_list:
            split_index = None
            for j in i:
                if not j.isdigit():
                    split_index = i.index(j)
                    break
            if i[split_index:] in vars_dict:
                vars_dict[i[split_index:]] += int(i[:split_index])
            else:
                vars_dict[i[split_index:]] = int(i[:split_index])
    sum_string = ''
    for k,v in vars_dict.iteritems():
        if sum_string:
            sum_string += '+%s%s' % (v,k)
        else:
            sum_string += '%s%s' % (v,k)
    return sum_string
</code></pre>
