title: Python: how to reference a variable in a dict?
body: <p>How do i reference a variable from an instance in a dict?     </p>
  
  <p>this code:</p>
  
  <pre><code>class Gold():
      def __init__(self):
          self.amount = 10
  
  class Cheese():
      def __init__(self, gold):
          self.gold = gold
          self.wallet = {'gold' : self.gold.amount}
          self.charge ={'gold' : 10}
  
      def subtract(self):
          for cat, cost in self.charge.iteritems():
              if self.wallet[cat] &gt;= cost:
                  self.wallet[cat] -= cost
  
  gold = Gold()
  cheese = Cheese(gold)
  cheese.subtract()
  print 'gold amount =', cheese.gold.amount, 'wallet =', cheese.wallet
  </code></pre>
  
  <p>yields:</p>
  
  <pre><code>gold amount = 10 wallet = {'gold': 0}
  </code></pre>
  
  <p>and not</p>
  
  <pre><code>gold amount = 0 wallet = {'gold': 0}
  </code></pre>
  
  <p>in the actual code i dont want a whole list of 'if' statements. so i couple a dict with all the costs (charge) in this example to a dict with all the actual values so i dont have to do</p>
  
  <pre><code>if cost == 'gold':
      pass
  if cost == 'action points':
      pass
  </code></pre>
  
  <p>etc</p>
  
  <p>any tips on how to do this?
  in the end the quistion is:</p>
  
  <pre><code>a = 1
  b = a
  </code></pre>
  
  <p>is there a way to update both a and b (b += 1 only updates b to 2)</p>