I have defined a function
def enumerateSpin(n): s = [] for a in range(0,3**n): ternary_rep = np.base_repr(a,3) k = len(ternary_rep)