My example dictionary is this
data_dictionary = {1:'blue',2:'green',3:'red',4:'orange',5:'purple',6:'mauve'}
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 .
I need to assemble a list from this. Pretty easy:
for payload_index in data_dictionary :
assembled_packet.append(data_dictionary[payload_index])
My problem is I need to always skip the 3rd element. I guess I could do an if but that would be inefficient:
for payload_index in data_dictionary :
if payload_index <> 3:
assembled_packet.append(data_dictionary[payload_index])
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:
#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])
Any ideas? Thanks!
inefficient? That seems like a premature optimisation! Just use normal code:
or even better:
Of course, you could just simply do:
P.S.
<>is long since deprecated.