def det(A):
    """Computes the determinant of a square matrix A using co-factor
    expansion. Assumes A is an nxn but does not assume a specific n.

    >>> A = [
    ... [4, 3, 2, 1],
    ... [0, 2, 1, 4],
    ... [0, 0, 4, 3],
    ... [0, 0, 0, 2]]
    >>> det(A)
    64
    """
    if not A:
        return 1
    subA = lambda i: [row[:i] + row[i+1:] for row in A[1:]]
    is_neg = lambda i: pow(-1, i % 2)  # makes even pos, but odd neg
    return sum(v * is_neg(i) * det(subA(i)) for i, v in enumerate(A[0]))