Splitting a string by capital letters
<p>I currently have the following code, which finds capital letters in a string 'formula': <a href="http://pastebin.com/syRQnqCP" rel="nofollow">http://pastebin.com/syRQnqCP</a></p>

<p>Now, my question is, how can I alter that code (Disregard the bit within the "if choice = 1:" loop) so that each part of that newly broken up string is put into it's own variable?</p>

<p>For example, putting in NaBr would result in the string being broken into "Na" and "Br". I need to put those in separate variables so I can look them up in my CSV file. 
Preferably it'd be a kind of generated thing, so if there are 3 elements, like MgSO4, O would be put into a separate variable like Mg and S would be.</p>

<p>If this is unclear, let me know and I'll try and make it a bit more comprehensible... No way of doing so comes to mind currently, though. :(</p>

<p>EDIT: Relevant pieces of code:</p>

<p>Function:</p>

<pre><code>def split_uppercase(string):
x=''
for i in string: 
    if i.isupper(): x+=' %s' %i 
    else: x+=i 
return x.strip()
</code></pre>

<p>String entry and lookup: </p>

<pre><code>formula = raw_input("Enter formula: ")
upper = split_uppercase(formula)

#Pull in data from form.csv
weight1 = float(formul_data.get(element1.lower()))
weight2 = float(formul_data.get(element2.lower()))
weight3 = float(formul_data.get(element3.lower()))


weightSum = weight1 + weight2 + weight3
print "Total weight =", weightSum
</code></pre>
