Python list of variables inside a class
Question: this is my first question, and combined with my being fairly noob feel free to
tell me if there is a completely different way I should be going about this!

Anyways, I am building a program that involves coloring a map with the four
color theorem in Python 2.7, attempting to use certain colors as much as
possible, and I ran into a problem when running something like this code:

In one module:

    
    
    class state:
        a = 0
        b = 0
        variable_list = [a,b]
    

Then I import that module into my main program:

    
    
    from State import state  //State(uppercase "s") is the .py file with the state class in it
    
    instance = state()
    
    instance.a = 1
    
    print instance.variable_list[0]
    

...and the program prints 0, despite changing it in the main program. Any
thoughts on how to update instance.variable_list with the change?


Answer: You have to think of Python variables in terms of pointers. Your question
really boils down to the following:

    
    
    >>> a = 42
    >>> l = [a]
    >>> a = 0
    >>> print l[0]  # shouldn't this print 0?
    42
    

The answer is no, because re-assigning `a` has nothing to do with the list
`l`. The list contains pointers to certain objects in memory. `l[0]` happens
to be pointing to the same object as `a` (the int `42`). When we reassign `a`,
we simply have it "point" to a new object in memory (the int `0`). This has no
bearing on the list `l`.

It looks like this:

    
    
    **a = 42
    l = [a]**
                          +----+
                a  -----> | 42 | &lt------; l[0]
                          +----+
    
    **a = 0**
                          +----+
                l[0] ---> | 42 |
                          +----+
    
                          +---+
                a ------> | 0 |
                          +---+
    

Notice that `l[0]` has not changed.

