Passing arguments in class in Python
Question: In the given code, lists x and y are randomly assigned numbers between 0-N
with some probability 0.5. I am randomly choosing an agent and removing it
using func1. I am adding one agent using func2. Now I have defined two class
objects x1 and x2. The input argument 'state1' of x2 is obtained from x1, and
similarly 'state2' of x1 is obtained from x2.

I am not able to find a proper way for passing arguments 'state2' and 'state1'
in x1 and x2. As you can see from last four lines of my code, state1 and
state2 should be defined before x1 and x2 but I can't do that as class objects
x1 and x2 should be defined first as I did.

What I am trying to achieve here is following: I have two populations N1 and
N2. I am randomly choosing one agent(say state1) from N1 and adding
it(preserving its state=state1) to N2. At the same time, I am removing one
agent from N2(say state2) and adding it(preserving its state=state2) to N1
population. This process is being repeated over time with fixed time interval.

Can somebody tell me a proper way to do it and make code run ?

    
    
    import random
    
    class func():
        def __init__(self, N, state):
            self.N = N
            self.x = []
            self.y = []
    
            agents = range(self.N)
    
            for i in range(self.N):
                if random.random() < 0.5:
                    self.x.append(i)
                else:
                    self.y.append(i)
    
            agent = random.choice(agents)
    
        def func1(self, agent):
            if self.agent in self.x:
                self.x.remove(agent)
                return 1
            elif self.agent in self.y:
                self.y.remove(agent)
                return 2
    
        def func2(self, state):
            if state == 1:
                self.x.append(N)
                return self.x
            elif state == 2:
                self.y.append(N)
                return self.y
    
    if __name__=='__main__':
    
        N1 = 100
        N2 = 100
        x1 = state(N1, state2)
        x2 = state(N2, state1)
    
        state1 = func.func1()
        state2 = func.func1()
    


Answer: You can remove the second argument from the state constructor and pass it
later, in a separate method like `set_state(state)`.

E.g.:

    
    
    x1 = state(N1)
    x2 = state(N2)
    
    state1 = func.func1()
    state2 = func.func2()
    
    setState(x1, state2)
    setState(x2, state1)
    

In the state function you have to strip the state argument and related code to
the new function setState. I do not see that code so I cannot show that here.

