def necklaces(n, k, free=False):
 return uniq((minlex(i, directed=(not free)) for i in variations(list(range(k)), n, repetition=True)))

def necklaces ( n , k , free = False ) : return uniq ( ( minlex ( i , directed = ( not free ) ) for i in variations ( list ( range ( k ) ) , n , repetition = True ) ) )
a routine to generate necklaces that may or may not be turned over to be viewed .