sets and maps hashset membership def __contains__(selfitem)idx hash(itemlen(self itemswhile self items[idx!noneif self items[idx=itemreturn true idx (idx len(self items return false finding an item results in ( amortized complexity as well the chains are kept short as long as most hash values are evenly distributed and the load factor is kept from approaching iterating over set to iterate over the items of set we need to define the __iter__ method to yield the elements of the hashset the method traverses the list of items skipping over placeholder elements and none references here is the code for the iterator def __iter__(self)for in range(len(self items))if self items[ !none and type(self items[ ]!hashset __placeholderyield self items[iother set operations many of the other set operations on the hashset are left as an exercise for the reader howevermost of them can be implemented in terms of the methods already presented in this consider the difference_update method it can be implemented using the iteratorthe membership testand the discard method the code in sect provides the implementation for the difference_update method hashset difference update def difference_update(selfother)for item in otherself discard(itemthe difference_update method presented in sect is mutator method because it alters the sequence referenced by self compare that with the difference method in sect which does not mutate the object referenced by self insteadthe difference method returns new set which consists of the difference of self and the other set this copy belongs to 'acha