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 9223893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:11:01+00:00 2026-06-18T04:11:01+00:00

Here is a simplified version of what I’m trying to do: class a(): Requirement

  • 0

Here is a simplified version of what I’m trying to do:

class a():
    Requirement = 0
    def func(self, oldlist, x):
        newlist = [None]*3
        newlist = oldlist
        newlist[x]  = b()
        print "Class a"
        g(newlist)


class b():
    Requirement = 1


def g(list):
    for i in range(3):
        if list[i].Requirement==0:
            list[i].func(list,i)

Initiallist=[None]*3
Initiallist[0]=a()
Initiallist[1]=b()
Initiallist[2]=a()
g(Initiallist)      

Instead of trying to express what I expect in words, I made some diagrams that express what in my mind should happen:

enter image description here

Which would imply that the function inside class a should be called 4 times. However, it only gets called 2 times, so it seems that this is happening:

enter image description here

I don’t understand why this is happening or how I should fix it.

  • 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-18T04:11:02+00:00Added an answer on June 18, 2026 at 4:11 am

    Not sure, but I think your problem is this line:

    newlist = oldlist
    

    I guess you want to copy the list (and not altering oldlist), so you should simply use:

    newlist = oldlist[:]
    

    So changing func to

    def func(self, oldlist, x):
        newlist = oldlist[:]
        newlist[x] = b()
        print "".join(x.__class__.__name__ for x in newlist)
        g(newlist)
    

    prints

    bba
    bbb
    abb
    bbb

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

Sidebar

Related Questions

Here is simplified version of my requirement I have a java class say Processor
Here's a simplified version of some code I wrote: class InfiniteLoop def run trap('SIGTERM')
Here is a simplified version of what I'm trying to do through an expression.
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =
Here is a simplified version of something I'm trying to run: for (var i
Here is a simplified version of what I'm trying to do: Without having multiple
I'm trying to create a large XML tree in R. Here's a simplified version
Here is very simplified version of code that i have: class PrintJob : IEntity
Here is a simplified version of a stored procedure I am trying to write
Here's a simplified version of my class: public abstract class Task { private static

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.