def isnested(A, B, namespace=None):
 if (namespace is not None):
  A = copy.copy(A)
  A.namespace = namespace
  B = copy.copy(B)
  B.namespace = namespace
 a = A(values=True)[0]
 b = B(values=True)[0]
 if (len(a) != len(b)):
  raise ValueError('A() and B() should be sequences of the same length')
 nA = len(set(a))
 nB = len(set(b))
 n = max(nA, nB)
 AB = [(a[i], b[i]) for i in range(len(a))]
 nAB = len(set(AB))
 if (nAB == n):
  if (nA > nB):
   F = A
  else:
   F = B
  return (True, F)
 else:
  return (False, None)

def isnested ( A , B , namespace = None ) : if ( namespace is not None ) : A = copy . copy ( A ) A . namespace = namespace B = copy . copy ( B ) B . namespace = namespace a = A ( values = True ) [ 0 ] b = B ( values = True ) [ 0 ] if ( len ( a ) != len ( b ) ) : raise ValueError ( 'A() and B() should be sequences of the same length' ) nA = len ( set ( a ) ) nB = len ( set ( b ) ) n = max ( nA , nB ) AB = [ ( a [ i ] , b [ i ] ) for i in range ( len ( a ) ) ] nAB = len ( set ( AB ) ) if ( nAB == n ) : if ( nA > nB ) : F = A else : F = B return ( True , F ) else : return ( False , None )
is factor b nested within factor a or vice versa: a very crude test which depends on the namespace .