def add(self, value):
    self._od[value] = None

def discard(self, value):
    self._od.pop(value, None)


class OrderedWeakrefSet(weakref.WeakSet):

    def __init__(self, values=()):
        super(OrderedWeakrefSet, self).__init__()
self.data = OrderedSet()
for elem in values:
    self.add(elem)
Indexable weak ordered set in Python