title: In class object, how to auto update attributes?
body: <p>I have a class which has multiple attributes that are related, for example:</p>
  
  <pre><code>class SomeClass：
      def __init__(self, n=0):
          self.list = range(n)
          self.listsquare = [ x**2 for x in self.list ]
  </code></pre>
  
  <p>If I make an object normally that would no problem, with</p>
  
  <pre><code>a = SomeClass(10)
  </code></pre>
  
  <p>I will get 2 lists, <code>a.list</code> and <code>a.listsquare</code>.</p>
  
  <p>Now if I want to make a empty object first, and assign one attribute to it, I want the other attributes to be automatically updated, for example if I do</p>
  
  <pre><code>b = SomeClass()
  b.list = range(5,10)
  </code></pre>
  
  <p>I want <code>b.listsquare</code> to be automatically updated, and also the other way around (assign <code>b.listsquare</code> and auto update <code>b.list</code>). Is this possible? Is <em>Class</em> the right choice for this?</p>
  
  <hr>
  
  <p>Thanks to you all, but I'm completely overwhelmed by all the different answers. Can anyone give a complete solution so I can learn write my own?</p>
  
  <p>I would like to achieve a class <code>Foo</code> with 3 attributes <code>length</code>, <code>list</code> and <code>listsquare</code> such that:</p>
  
  <ol>
  <li>If I do <code>a = Foo(3)</code>, I get <code>a.length = 3</code>, <code>a.list = [0, 1, 2]</code>, <code>a.listsquare = [0, 1, 4]</code>.</li>
  <li>If I do <code>b = Foo().list = [5, 6]</code>, I get <code>b.length = 2</code>, <code>b.listsquare = [25, 36]</code>.</li>
  <li>If I do <code>c = Foo().listsquare = [4, 9]</code>, I get <code>c.length = 2</code>, <code>c.list = [2, 3]</code>.</li>
  </ol>