def _format(self, obj, indent, allowance, context, level):
        level = level + 1
        objid = id(obj)
        if context in objid:
            self._io.write(_recursion(obj))
            return
        rep = self._repr(obj, context, level - 1)
        typ = type(obj)
        sep_lines = len(rep) > (self._termwidth - 1 - indent - allowance)
        write = self._io.write

        if sep_lines:
            if typ is dict:
                write('{\n  ')
                length = len(obj)
                if length:
                    context[objid] = 1
                    indent = indent + 2
                    items  = obj.items()
                    items.sort()
                    key, ent = items[0]
                    rep = self._repr(key, context, level)
                    write(rep)
                    write(': ')
                    self._format(ent, indent + len(rep) + 2, allowance + 1, context, level)
                    if length > 1:
                        for key, ent in items[1:]:
                            rep = self._repr(key, context, level)
                            write(',\n%s%s: ' % (' '*indent, rep))
                            self._format(ent, indent + len(rep) + 2, allowance + 1, context, level)
                    indent = indent - 2
                    del context[objid]
                write('\n}')
                return

            if typ is list:
                write('[\n')
                self.print_list(obj, 2)
                write(']')
                return

            if typ is tuple:
                write('(\n')
                self.print_list(obj, 2)
                if len(obj) == 1:
                    write(',')
                write(')')
                return

        write(rep)
dataset/ETHPy150Open kdart/pycopia/CLI/pycopia/UI.py/UserInterface._format/swapped operands of `in`