def dihedral(n):
 if (n == 1):
  (yield Permutation([0, 1]))
  (yield Permutation([1, 0]))
 elif (n == 2):
  (yield Permutation([0, 1, 2, 3]))
  (yield Permutation([1, 0, 3, 2]))
  (yield Permutation([2, 3, 0, 1]))
  (yield Permutation([3, 2, 1, 0]))
 else:
  gen = list(range(n))
  for i in range(n):
   (yield Permutation(gen))
   (yield Permutation(gen[::(-1)]))
   gen = rotate_left(gen, 1)

def dihedral ( n ) : if ( n == 1 ) : ( yield Permutation ( [ 0 , 1 ] ) ) ( yield Permutation ( [ 1 , 0 ] ) ) elif ( n == 2 ) : ( yield Permutation ( [ 0 , 1 , 2 , 3 ] ) ) ( yield Permutation ( [ 1 , 0 , 3 , 2 ] ) ) ( yield Permutation ( [ 2 , 3 , 0 , 1 ] ) ) ( yield Permutation ( [ 3 , 2 , 1 , 0 ] ) ) else : gen = list ( range ( n ) ) for i in range ( n ) : ( yield Permutation ( gen ) ) ( yield Permutation ( gen [ : : ( - 1 ) ] ) ) gen = rotate_left ( gen , 1 )
generates the dihedral group of order 2n .