def rst_table(self, array):
        """Given an array, the function formats and returns and table in rST format."""
        # Determine cell width for each column
        cell_dict = {}
        for i, row in enumerate(array):
            for j, val in enumerate(row):
                if j not in cell_dict:
                    cell_dict[j] = []
                cell_dict[j].append(val)
        for item in cell_dict:
            cell_dict[item] = max([len(x) for x in cell_dict[item]]) + 1  # Contains adapted width for each column

        # Format top line
        num_cols = len(array[0])
        form = '+'
        for col in range(num_cols):
            form += (cell_dict[col] + 1) * '-'
            form += '+'
        form += '\n'

        # Format values
        for i, row in enumerate(array):
            form += '| '
            for j, val in enumerate(row):
                cell_width = cell_dict[j]
                form += str(val) + (cell_width - len(val)) * ' ' + '| '
            form.rstrip()
            form += '\n'

            # Seperation lines
            form += '+'
            if i == 0:
                sign = '='
            else:
                sign = '-'
            for col in range(num_cols):
                form += (cell_dict[col] + 1) * sign
                form += '+'
            form += '\n'
        return form
def rst_table ( self , array ) : cell_dict = { } for i , row in enumerate ( array ) : for j , val in enumerate ( row ) : if j not in cell_dict : cell_dict [ j ] = [ ] cell_dict [ j ] . append ( val ) for item in cell_dict : cell_dict [ item ] = max ( [ len ( x ) for x in cell_dict [ item ] ] ) + 1 num_cols = len ( array [ 0 ] ) form = '+' for col in range ( num_cols ) : form += ( cell_dict [ col ] + 1 ) * '-' form += '+' form += '\n' for i , row in enumerate ( array ) : form += '| ' for j , val in enumerate ( row ) : cell_width = cell_dict [ j ] form += str ( val ) + ( cell_width - len ( val ) ) * ' ' + '| ' form . rstrip ( ) form += '\n' form += '+' if i == 0 : sign = '=' else : sign = '-' for col in range ( num_cols ) : form += ( cell_dict [ col ] + 1 ) * sign form += '+' form += '\n' return form
Given an array, the function formats and returns and table in rST format.