def cycles(seq):
 n = len(seq)
 cycled_seq = cycle(seq)
 for x in seq:
  (yield tuple(islice(cycled_seq, n)))
  next(cycled_seq)

def cycles ( seq ) : n = len ( seq ) cycled_seq = cycle ( seq ) for x in seq : ( yield tuple ( islice ( cycled_seq , n ) ) ) next ( cycled_seq )
yields cyclic permutations of the given sequence .