Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 976109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:41:39+00:00 2026-05-16T03:41:39+00:00

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

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:41:40+00:00Added an answer on May 16, 2026 at 3:41 am

    inefficient? That seems like a premature optimisation! Just use normal code:

    for payload_index in data_dictionary:
        if payload_index != 3:
            assembled_packet.append(data_dictionary[payload_index])
    

    or even better:

    assembled_packet = [data_dictionary[index] for index in data_dictionary if index != 3]
    

    Of course, you could just simply do:

    >>> d = {1:'blue',2:'green',3:'red',4:'orange',5:'purple',6:'mauve'}
    >>> d.pop(3)
    'red'
    >>> list(d.values())        # in py3k; in python-2.x d.values() would do
    ['blue', 'green', 'orange', 'purple', 'mauve']
    

    P.S. <> is long since deprecated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have (for example) Dictionary of different generic types ( d1, d2, d3, d4
Up until now, I have maintained a 'dictionary' table in my database, for example:
I have this: dictionary = { (month, year) : [int, int, int] } I'd
When you try to access a key which isn't in a Dictionary (for example),
Because of some limitations ( example ) in the built-in ActionScript 3 Dictionary class
Is it possible to set code behind a resource dictionary in WPF. For example
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
I have this code: cursor.execute( ''' SELECT id,DISTINCT tag FROM userurltag ''') tags =
I have a dictionary to which I want to append to each drug, a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.