def permute_signs(t):
 for signs in cartes(*([(1, (-1))] * (len(t) - t.count(0)))):
  signs = list(signs)
  (yield type(t)([((i * signs.pop()) if i else i) for i in t]))

def permute_signs ( t ) : for signs in cartes ( * ( [ ( 1 , ( - 1 ) ) ] * ( len ( t ) - t . count ( 0 ) ) ) ) : signs = list ( signs ) ( yield type ( t ) ( [ ( ( i * signs . pop ( ) ) if i else i ) for i in t ] ) )
return iterator in which the signs of non-zero elements of t are permuted .