(l)
return ordered_l
Cyclic permutations based on canonical ordering

    This method does the sort based ascii values while
    a better approach would be to used lexicographic sort.
    TODO: Handle condition such as symbols have subscripts/superscripts
    in case of lexicographic sort
Cyclic permutations based on canonical ordering
Cyclic permutations based on canonical ordering
def _cycle_permute(l):
    """ Cyclic permutations based on canonical ordering

    This method does the sort based ascii values while
    a better approach would be to used lexicographic sort.
    TODO: Handle condition such as symbols have subscripts/superscripts
    in case of lexicographic sort

    """

    if len(l) == 1:
        return l

    min_item = min(l, key=default_sort_key)
    indices = [i for i, x in enumerate(l) if x == min_item]

    le = list(l)
    le.extend(l)  # duplicate and extend string for easy processing

    # adding the first min_item index back for easier looping
    indices.append(len(l) + indices[0])

    # create sublist of items with first item as min_item and last_item
    # in each of the sublist is item just before the next occurence of
    # minitem in the cycle formed.
    sublist = [[le[indices[i]:indices[i + 1]]] for i in
               xrange(len(indices) - 1)]

    # we do comparison of strings by comparing elements
    # in each sublist
    idx = sublist.index(min(sublist))
    ordered_l = le[indices[idx]:indices[idx] + len(l)]

    return ordered_l
def _cycle_permute ( l ) : if len ( l ) == 1 : return l min_item = min ( l , key = default_sort_key ) indices = [ i for i , x in enumerate ( l ) if x == min_item ] le = list ( l ) le . extend ( l ) # duplicate and extend string for easy processing # adding the first min_item index back for easier looping indices . append ( len ( l ) + indices [ 0 ] ) # create sublist of items with first item as min_item and last_item # in each of the sublist is item just before the next occurence of # minitem in the cycle formed. sublist = [ [ le [ indices [ i ] : indices [ i + 1 ] ] ] for i in xrange ( len ( indices ) - 1 ) ] # we do comparison of strings by comparing elements # in each sublist idx = sublist . index ( min ( sublist ) ) ordered_l = le [ indices [ idx ] : indices [ idx ] + len ( l ) ] return ordered_l