Sum possibilities, one loop
<p>Earlier I had a lot of wonderful programmers help me get a function done. however the instructor wanted it in a single loop and all the working solutions used multiple loops.</p>

<p>I wrote an another program that almost solves the problem. Instead of using a loop to compare all the values, you have to use the function has_key to see if that specific key exists. Answer of that will rid you of the need to iter through the dictionary to find matching values because u can just know if they are matching or not.
again, charCount is just a function that enters the constants of itself into a dictionary and returns the dictionary.</p>

<pre><code>def sumPair(theList, n):
    for a, b in level5.charCount(theList).iteritems():    
        x = n - a     
        if level5.charCount(theList).get(a):
            if a == x:
                if b &gt; 1: #this checks that the frequency of the number is greater then one so the program wouldn't try to multiply a single possibility by itself and use it (example is 6+6=12. there could be a single 6 but it will return 6+6
                    return a, x
            else:
                if level5.charCount(theList).get(a) != x:
                    return a, x           
print sumPair([6,3,8,3,2,8,3,2], 9)  
</code></pre>

<p>I need to just make this code find the sum without iteration by seeing if the current element exists in the list of elements.</p>
