<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def leaf_bus(self, df=False):
 """ Return leaf bus idx, line idx, and the line foreign key Returns ------- (list, list, list) or DataFrame """

        # leafs - leaf bus idx
        # lines - line idx
        # fkey - the foreign key of Line, in 'bus1' or 'bus2', linking the bus

        leafs, lines, fkeys = list(), list(), list()

        # convert to unique, ordered list
        buses = sorted(list(set(self.bus1 + self.bus2)))

        links = self.link_bus(buses)

        for bus, link in zip(buses, links):
            line = link[0]
            fkey = link[1]
            if line is None:
                continue
            if len(line) == 1:
                leafs.append(bus)
                lines.extend(line)
                fkeys.extend(fkey)

        # output formatting
        if df is False:
            return leafs, lines, fkeys
        else:
            _data = {'Bus idx': leafs, 'Line idx': lines, 'fkey': fkeys}
            if globals()['pd'] is None:
                globals()['pd'] = importlib.import_module('pandas')
            return pd.DataFrame(data=_data)