def alternating(n):
 for perm in variations(list(range(n)), n):
  p = Permutation(perm)
  if p.is_even:
   (yield p)

def alternating ( n ) : for perm in variations ( list ( range ( n ) ) , n ) : p = Permutation ( perm ) if p . is_even : ( yield p )
generates the alternating group of order n .