University of Arizona, Department of Computer Science

CSc 120: Column to List (Recursive)

Expected Behavior

Write a recursive function column2list_rec(grid, n), where grid is a list of lists and n is an integer, that returns a list consisting of the element at position n of each row of grid.

You can assume that 0n < len(r) for each row (i.e., element) of grid.

Programming Requirements

Solve this problem using recursion. You are allowed to use only the following programming constructs:

Solutions that go outside these constructs, e.g., by using for/while loops or list comprehensions, will not get credit.

Examples

In the examples below, x is assumed to be the following list of lists:
[ [ 'aa', 'bb', 'cc', 'dd' ],
  [ 'ee', 'ff', 'gg', 'hh', 'ii', 'jj' ],
  [ 'kk', 'll', 'mm', 'nn' ] ]
  1. column2list_rec(x,3)
    return value: ['dd', 'hh', 'nn' ]

  2. column2list_rec(x,0)
    return value: [ 'aa', 'ee', 'kk' ]