Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # [python - Combining and slicing tables - Stack Overflow](https://stackoverflow.com/questions/73614101/combining-and-slicing-tables)
- 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 colummn 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:
- rows = []
- for n in range(numcols):
- if n != col:
- rows.append(table[m][n])
- result.append(rows)
- return result
- print(func([[1,3,5], [6,2,7], [5,8,4]],1,2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement