Combining and slicing tables

Viewed 34

I'm trying to write a function that takes in tables and deletes specified objects and columns (Check out spec below). The code I'm writing gets me nearly there but its combining the separate lists instead of keeping them separate. Can anyone help me get the rest of the way?

def func(table,row,col):
    """
    Returns a copy of the table, removing the given row and column.
      
    Examples:
        func([[1,3,5],[6,2,7],[5,8,4]],1,2) returns [[1,3],[5,8]]
    
    Parameter table: the nested list to process
    Precondition: table is a table of numbers of the same length.

    Parameter row: the row to remove
    Precondition: row is an index (int) for a row of table
    
    Parameter col: the column to remove
    Precondition: col is an index (int) for a column of table
    """
    numrows=len(table)
    numcols=len(table[0])

    result= []

    for m in range(numrows):
        if m == row:
            pass
        else:
            for n in range(numcols):
                rows=[]
                if n == col:
                    pass
                else:
                    rows=rows+[table[m][n]]
                    result=result+rows
    
    return result
0 Answers
Related