<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def connected(self, tables, cols, find_connections=False):
        '''
        Returns a list of tuples of connected table pairs.

            :param tables: a list of table names
            :param cols: a list of column names
            :param find_connections: set this to True to detect relationships from column names.

            :return: a tuple (connected, pkeys, fkeys, reverse_fkeys)
        '''
        connected = defaultdict(list)
        fkeys = defaultdict(set)
        reverse_fkeys = {}
        pkeys = {}
        with self.connect() as con:
            fk_result = self.foreign_keys()
            if find_connections:
                for table in tables:
                    for col in cols[table]:
                        if col.endswith('_id'):
                            ref_table = (col[:-4] + 'ies') if col[-4] == 'y' and col[-5] != 'e' else (col[:-3] + 's')
                            if ref_table in tables:
                                connected[(table, ref_table)].append((col, 'id'))
                                connected[(ref_table, table)].append(('id', col))
                                fkeys[table].add(col)
                                reverse_fkeys[(table, col)] = ref_table
                        if col == 'id':
                            pkeys[table] = col
            for (table, col, ref_table, ref_col) in fk_result:
                connected[(table, ref_table)].append((col, ref_col))
                connected[(ref_table, table)].append((ref_col, col))
                fkeys[table].add(col)
                reverse_fkeys[(table, col)] = ref_table

            tbl_col_names = self.table_column_names()
            for (table, pk) in tbl_col_names:
                pkeys[table] = pk

        return connected, pkeys, fkeys, reverse_fkeys