Converting from a double loop to a single loop
<p>This program builds a dictionary out of a list based on what two index numbers you would like from the list.
this is the output  </p>

<p>{'a': 2, 'c': 7, 'b': 'h'}</p>

<pre><code>def buildDict2(theList,inputOne,inputTwo) :
    newdict={}
    for a in theList:
        if inputTwo &gt;= len(a):
                print "error"
                return "error"
        if inputOne &gt;= len(a):
                print "error"
                return "error"
        for oneValue in a: 
                    print len(a)

                    varkey=a[inputOne]
                    varvalue=a[inputTwo]
                    newdict[varkey]=varvalue


    return newdict
print buildDict2([["a", "s","d", 2,0,1],["b", "f",3,"h",0,2],["c", "g",5,7]],0,3)
</code></pre>

<p>How do i convert this to a single loop? 
+1 all answers
thank you for your help, it is greatly appreciated. </p>

<p>basically i just need to use one loop instead of two</p>

<p>edit: important concept: it takes a dictionary and two numbers. the two numbers tell the program what index of the lists to use. list=[[a,b,c],[d,e,f],[h,g,i]] used with the numbers 0 and 2 will return a dictionary with three entries. the keys will be the first input. so the keys are a d and h, and the values are going to be the list index of second input, so c, e i. get it?</p>

<p>for this code</p>

<pre><code>def buildDict2(theList, range1, range2, newdict = {}):
    for a in theList:
        if range2 &gt;= len(a) or range1 &gt;= len(a):
            return "error"
        newdict[a[range1]] = a[range2]
        return newdict
print buildDict2([["a", "s","d", 2,0,1],["b", "f",3,"h",0,2],["c", "g",5,7]],0,3)
</code></pre>

<p>i am getting {'a': 2}
when i want to get 
{'a': 2, 'c': 7, 'b': 'h'}
whats the problem?</p>
