title: python: how to have a property and with a setter function that detects all changes that happen to the value
body: <p>I have a two properties which holds lists. Whenever any item in this list changes, I would like the other list to update itself. This includes the statement <code>obj.myProp[3]=5</code>. Right now, this statement calls the getter function to get the whole list, gets the third item from the list, and sets that to 5. the <code>myProp</code> list is changed, but the second list never gets updated.</p>
  
  <pre><code>class Grid(object):
  
      def __init__(self,width=0,height=0):
  
          # Make self._rows a multi dimensional array
          # with it's size width * height
          self._rows=[[None] * height for i in xrange(width)]
          # Make `self._columns` a multi dimensional array
          # with it's size height * width
          self._columns=[[None] * width for i in xrange(height)]
  
      @property
      def rows(self):
          # Getting the rows of the array
          return self._rows
  
      @rows.setter
      def rows(self, value):
          # When the rows are changed, the columns are updated
          self._rows=value
          self._columns=self._flip(value)
  
      @property
      def columns(self):
          # Getting the columns of the array
          return self._columns
  
      @columns.setter
      def columns(self, value):
          # When the columns are changed, the rows are updated
          self._columns = value
          self._rows = self._flip(value)
  
      @staticmethod
      def _flip(args):
          # This flips the array
          ans=[[None] * len(args) for i in xrange(len(args[0]))]
          for x in range(len(args)):
              for y in range(len(args[0])):
                  ans[y][x] = args[x][y]
          return ans
  </code></pre>
  
  <p>Example run:</p>
  
  <pre><code>&gt;&gt;&gt; foo=grid(3,2)
  &gt;&gt;&gt; foo.rows
  [[None, None], [None, None], [None, None]]
  &gt;&gt;&gt; foo.columns
  [[None, None, None], [None, None, None]]
  &gt;&gt;&gt; foo.rows=[[1,2,3],[10,20,30]]
  &gt;&gt;&gt; foo.rows
  [[1, 2, 3], [10, 20, 30]]
  &gt;&gt;&gt; foo.columns
  [[1, 10], [2, 20], [3, 30]]
  &gt;&gt;&gt; foo.rows[0][0]=3
  &gt;&gt;&gt; foo.rows
  [[3, 2, 3], [10, 20, 30]]
  &gt;&gt;&gt; foo.columns
  [[1, 10], [2, 20], [3, 30]]
  </code></pre>
  
  <p>If you look at the last three lines, this is where the actual problem occurs. I set the first item of the sublist to three, but <code>foo.columns</code> never updates itself to put the 3 in its list.</p>
  
  <p>So in short, how do I make a variable that always updates another variable, even when it's subitem is being changed?</p>
  
  <p>I'm using Python 2.7</p>