class Item(object):
    all = weakref.WeakValueDictionary()

def __init__(self, uniq_key, title=None):
    self._key = uniq_key
self.title = title
self.all[self._key] = self

def adjust_key(self, newkey):
    del self.all[self._key]
self.all[newkey] = self
self._key = newkey

def get_key(self):
    return self._key
key = property(get_key, adjust_key)
Python data structure for a collection of objects with random access based on an attribute