Ask Your Question

Revision history [back]

For matrices, I don't know, this is a complex topic in Sage. For tuple of pairs, this is pure Python, and I suggest:

def is_a_pair(a):
    return isinstance(a,tuple) and len(a)==2
def is_a_tuple_of_pairs(A):
    if not isinstance(A,tuple):
        return False
    return all (is_a_pair(a) for a in A)

For matrices, I don't know, this is a complex topic in Sage. For tuple tuples of pairs, this is pure Python, and I suggest:

def is_a_pair(a):
    return isinstance(a,tuple) and len(a)==2
def is_a_tuple_of_pairs(A):
    if not isinstance(A,tuple):
        return False
    return all (is_a_pair(a) for a in A)

For matrices, I don't know, this is a complex topic in Sage. For tuples of pairs, this is pure Python, and I suggest:

def is_a_pair(a):
    return isinstance(a,tuple) and len(a)==2
def is_a_tuple_of_pairs(A):
    if not isinstance(A,tuple):
        return False
    return all (is_a_pair(a) for a in A)

Note that if you accept lists in addition to tuples, you can use:

isinstance(a,(list,tuple))

inside these functions and so on.