human
Complete this python program:
def _set_pprinter_factory(start, end, basetype):
assistant
#Here is the Python program you requested.

    """Factory that returns a pprint function useful for sets and frozensets.
    """
    def inner(obj, p, cycle):
        typ = type(obj)
        if ((basetype is not None) and (typ is not basetype) and (typ.__repr__ != basetype.__repr__)):
            return p.text(typ.__repr__(obj))
        if cycle:
            return p.text(((start + '...') + end))
        if (len(obj) == 0):
            p.text((basetype.__name__ + '()'))
        else:
            step = len(start)
            p.begin_group(step, start)
            items = obj
            if (not (p.max_seq_length and (len(obj) >= p.max_seq_length))):
                try:
                    items = sorted(obj)
                except Exception:
                    pass
            for (idx, x) in p._enumerate(items):
                if idx:
                    p.text(',')
                    p.breakable()
                p.pretty(x)
            p.end_group(step, end)
    return inner