Accessing only part of a dictionary in a for using Python
<p>My example dictionary is  this</p>

<pre><code>data_dictionary = {1:'blue',2:'green',3:'red',4:'orange',5:'purple',6:'mauve'}
</code></pre>

<p>The data_dictionary can have more elements depending on the incoming data . The first value is what we call a payload_index. I always get payload_index 1 to 4 .</p>

<p>I need to assemble a list from this. Pretty easy:</p>

<pre><code>for payload_index in data_dictionary :
            assembled_packet.append(data_dictionary[payload_index])
</code></pre>

<p>My problem is I need to always skip the 3rd element. I guess I could do an if but that would be inefficient:</p>

<pre><code>for payload_index in data_dictionary :
            if payload_index &lt;&gt; 3:
                assembled_packet.append(data_dictionary[payload_index])
</code></pre>

<p>I could do it in two steps and do the first three elements but the problem is I cannot figure out how to get the rest since the number of elements after the 3rd varies. I tried using an impossibly high index (below) but that obviously fails:</p>

<pre><code>#get element 1 and two
for index in range(0,3):
            assembled_packet.append(data_dictionary[index])

#get element 1 and two
for index in range(4,999):
            assembled_packet.append(data_dictionary[index])
</code></pre>

<p>Any ideas? Thanks!</p>
