append values to dictionary depending on length?
<p>I have a list of lists <code>uarfcnrssi2</code> and a dictionary of lists <code>band2</code>. I then have certain conditions under which values from uarfcnrssi2 are added to band2, as shown below:</p>

<pre><code>uarfcnrssi2=[[10564, 20, 1],[10637, 26, 1], [10662, 32, 1], [10712, 26, 1], [10837, 15, 1], [10837, 17, 1],
 [2, 10, 13], [3, 18, 13], [44, 12, 13], [10564, 27, 13], [49, 15, 13], [64, 20, 13], [66, 19, 13], [976, 27, 13], [981, 21, 13], [982, 20, 13], [985, 13, 13], [988, 13, 13], [788, 12, 11]]      

band2= {'channel1': 10564, 'channel2': 10589, 'channel3': 10612, 'channel4': 10637,'channel5': 10662, 'channel6': 10687,
'channel7': 10712, 'channel8': 10737, 'channel9': 10762, 'channel10': 10787,'channel11': 10812, 'channel12': 10837, }
var1 = 5
var2 = -190
band2 = {k: [v, v/var1, v/var1+var2] for k, v in band2.iteritems()
</code></pre>

<p>Code: </p>

<pre><code>for k, v in band2.items():
    for i in uarfcnrssi2:
        if v[0] == i[0] and i[2] == 1 and len(v)&lt;=3:
            band2[k].append(i[1])
</code></pre>

<p>I now have a dictionary like this:             </p>

<pre><code>{'channel11': [10812, 2162, 1972], 'channel10': [10787, 2157, 1967], 'channel3': [10612, 2122, 1932], 'channel2': [10589, 2117, 1927], 'channel1': [10564, 2112, 1922, 20], 'channel7': [10712, 2142, 1952, 26], 'channel6': [10687, 2137, 1947], 'channel5': [10662, 2132, 1942, 32], 'channel4': [10637, 2127, 1937, 26], 'channel9': [10762, 2152, 1962], 'channel8': [10737, 2147, 1957], 'channel12': [10837, 2167, 1977, 15]}   
</code></pre>

<p>However for the lists that I did not append a 4th item to I want <code>0</code> to be appended to the end of each, I have no problem looping again to do this, but is there a way to edit my code above to do that?</p>

<p>EDIT: Way I did it that I want to improve</p>

<pre><code>for k, v in band2.items():
    for i in uarfcnrssi2:
        if v[0] == i[0] and i[2] == 1 and len(v)&lt;=3:
            band2[k].append(i[1])

for k, v in band2.items():
    if len(v) &lt;=3:
        band2[k].append(0)
print band2  
</code></pre>

<p>Final output:</p>

<pre><code>band2 = {'channel11': [10812, 2162, 1972, 0], 'channel10': [10787, 2157, 1967, 0], 'channel3': [10612, 2122, 1932, 0], 'channel2': [10589, 2117, 1927, 0], 'channel1': [10564, 2112, 1922, 20], 'channel7': [10712, 2142, 1952, 26], 'channel6': [10687, 2137, 1947, 0], 'channel5': [10662, 2132, 1942, 32], 'channel4': [10637, 2127, 1937, 26], 'channel9': [10762, 2152, 1962, 0], 'channel8': [10737, 2147, 1957, 0], 'channel12': [10837, 2167, 1977, 15]}
</code></pre>
