Manipulating list of lists and dictionary
<p>I have a list of lists representing the keys in a dictionary. I wish to pickup the smaller key for each list in lists. For instance,</p>

<pre><code>L1 = [['1_A','2_A'],['1_B','2_B']]
D1 = {'1_A': 0.22876, '2_A': 0.22382, '1_B': 0.2584, '2_B': 0.25373}

for li in L1:
    for ll in li:
        if ll in D1.keys():
            print "Value for %s is %s" %(ll,D1[ll])
        else:
            print "Values not found"
</code></pre>

<p>When I print it, I get:</p>

<pre><code>Value for 1_A is 0.22876
Value for 2_A is 0.22382
Value for 1_B is 0.2584
Value for 2_B is 0.25373
</code></pre>

<p>The output I expect is <code>2_A</code>, <code>2_B</code> since both of them have smaller values compared to <code>1_A</code> and <code>1_B</code> respectively. Can anyone suggest how to do this?</p>

<p>You're not comparing the values anywhere.</p>

<pre><code>L1 = [['1_A','2_A'],['1_B','2_B']]
D1 = {'1_A': 0.22876, '2_A': 0.22382, '1_B': 0.2584, '2_B': 0.25373}

template = "Value for {} is {}"

for i,j in L1:
    if D1[i] &lt; D1[j]:
        print template.format(i,D1[i])
    else:
        print template.format(j,D1[j])
</code></pre>

python python-2.7 dictionary