 <p>Give your <code>cell</code> class an <code>address</code> attribute, which is a two-tuple, e.g. <code>(0,0)</code>. Give the <code>cell</code> class a <code>__hash__</code> method, which returns <code>hash(self.address)</code>.</p> <pre><code>class cell: def __init__(self,address): self.address = address def __hash__(self): return hash(self.address) def __eq__(self): return hash(self) == hash(other) </code></pre> <p>You can still access cells by their address, but the cells know where they belong.</p> <pre><code>&gt;&gt;&gt; c = cell((0,0)) &gt;&gt;&gt; c &lt;so.cell instance at 0xb74c6a2c&gt; &gt;&gt;&gt; grid = dict() &gt;&gt;&gt; grid[c] = c &gt;&gt;&gt; grid[c] &lt;so.cell instance at 0xb74c6a2c&gt; &gt;&gt;&gt; grid[(0,0)] &lt;so.cell instance at 0xb74c6a2c&gt; </code></pre> <p>I'm not sure what else your <code>cell</code>s need to know and/or do, but if you're just doing numerical stuff here, I'd highly recommend the <a href="http://docs.scipy.org/doc/scipy/reference/sparse.html" rel="nofollow">scipy.sparse</a> module.</p>