def pop(self, last=True):
    if (not self):
        raise KeyError('set is empty')
    key = (next(reversed(self)) if last else next(iter(self)))
    self.discard(key)
    return key
def pop(self, last=True):
    if (not self):
        raise KeyError('set is empty')
    key = (next(reversed(self)) if last else next(iter(self)))
    self.discard(key)
    return key