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

  • Home
  • SEARCH
  • 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 8622359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:02:07+00:00 2026-06-12T07:02:07+00:00

I am relatively new in Python so facing difficulties in basics. I have following

  • 0

I am relatively new in Python so facing difficulties in basics. I have following code that prints proper list value within loop but outside of loop it only shows the last value:

for item in statusEntries:
        theNameStatus = item[3] #get the numStatus field data
        if theNameStatus == 1:
            numStatus1 = item[2] #get cntStatus
        elif theNameStatus == 2:
            if numStatus1 > 0:
                theNameStatus = "closed"

        sctStatus["nameStatus"] = theNameStatus
        sctStatus["IDstatus"] = item[0]
        sctStatus["cntStatus"] = item[2]
        #Appending Status Array with Status Attribute Object
        sctResponse["STATUSOPTION"].append(sctStatus)

When I print sctResponse[“STATUSOPTION”] within loop then it shows proper values with each iteration but when it reaches on last iteration it just fills it with last loop values:

{'STATUSOPTION': [{'nameStatus': 1, 'cntStatus': 0, 'IDstatus': 6}]}
{'STATUSOPTION': [{'nameStatus': 2, 'cntStatus': 0, 'IDstatus': 1}, {'nameStatus': 2, 'cntStatus': 0, 'IDstatus': 1}]}
{'STATUSOPTION': [{'nameStatus': 3, 'cntStatus': 0, 'IDstatus': 7}, {'nameStatus': 3, 'cntStatus': 0, 'IDstatus': 7}, {'nameStatus': 3, 'cntStatus': 0, 'IDstatus': 7}]}
{'STATUSOPTION': [{'nameStatus': 4, 'cntStatus': 0, 'IDstatus': 4}, {'nameStatus': 4, 'cntStatus': 0, 'IDstatus': 4}, {'nameStatus': 4, 'cntStatus': 0, 'IDstatus': 4}, {'nameStatus': 4, 'cntStatus': 0, 'IDstatus': 4}]}

{‘STATUSOPTION’: [{‘nameStatus’: 5, ‘cntStatus’: 0, ‘IDstatus’: 5}, {‘nameStatus’: 5, ‘cntStatus’: 0, ‘IDstatus’: 5}, {‘nameStatus’: 5, ‘cntStatus’: 0, ‘IDstatus’: 5}, {‘nameStatus’: 5, ‘cntStatus’: 0, ‘IDstatus’: 5}, {‘nameStatus’: 5, ‘cntStatus’: 0, ‘IDstatus’: 5}]}

As you can see the last bold record, all values wipied out and it filled it with last record. Why is it happening? Append should append rather than wiping it out, No?

  • 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-06-12T07:02:08+00:00Added an answer on June 12, 2026 at 7:02 am

    Assuming that the loop is as you’ve shown it, then it looks to me like there’s only one sctStatus dictionary, and you keep changing its "namestatus", "IDstatus", and "cntStatus" key-value pairs. Try inserting sctStatus = {}, i.e.

        sctStatus = {}
        sctStatus["nameStatus"] = theNameStatus
        sctStatus["IDstatus"] = item[0]
        sctStatus["cntStatus"] = item[2]
    

    so that you’re appending a new dictionary each time.

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

Sidebar

Related Questions

I am relatively new to Python, and I am experimenting with writing the following
I am relatively new to Python and was hoping someone could explain the following
Relatively new to python. I recently posted a question in regards to validating that
I'm new to Python (relatively new to programing in general) and I have created
So I am relatively new to python, and in order to learn, I have
I have the following (correct) solution to Project Euler problem 24. I'm relatively new
relatively new to python so excuse me if this has an obvious answer that
Relatively new to Python, and I saw the following construct in the PyFacebook library
I'm relatively new to python, have done it a bit for my physics university
I'm a relatively new convert to Python. I've written some code to grab/graph data

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.