Add up all posibilities in a list, with two variables
<p>I am trying to make a program in python that will accept a user's input and check if it is a Kaprekar number.
I'm still a beginner, and have been having a lot of issues, but my main issue now that I can't seem to solve is how I would add up all posibilities in a list, with only two variables. I'm probably not explaning it very well so here is an example:</p>

<p>I have a list that contains the numbers
<code>['2', '0', '2', '5']</code>.
How would I make python do <code>2 + 025</code>, <code>20 + 25</code> and <code>202 + 5</code>?</p>

<p>It would be inside an if else statement, and as soon as it would equal the user inputted number, it would stop.</p>

<p>Thanks</p>

<p>(<a href="http://pastebin.com/Kg9bQq47" rel="nofollow">Here</a> is what the entire code looks like if it helps- where it currently says <code>if  1 == 0:</code>, it should be adding them up.)</p>

<p>Say you start with</p>

<pre><code>a = ['2', '0', '2', '5']
</code></pre>

<p>Then you can run</p>

<pre><code>&gt;&gt;&gt;  [(a[: i], a[i: ]) for i in range(1, len(a))]
[(['2'], ['0', '2', '5']), (['2', '0'], ['2', '5']), (['2', '0', '2'], ['5'])]
</code></pre>

<p>to obtain all the possible contiguous splits. </p>

<p>If you want to process it further, you can change it to numbers via</p>

<pre><code>&gt;&gt;&gt; [(int(''.join(a[: i])), int(''.join(a[i: ]))) for i in range(1, len(a))]
[(2, 25), (20, 25), (202, 5)]
</code></pre>

<p>or add them up</p>

<pre><code>&gt;&gt;&gt; [int(''.join(a[: i])) + int(''.join(a[i: ])) for i in range(1, len(a))]
[27, 45, 207]
</code></pre>

python list add