def cycle_sort(sequence):
    """ Sort a sequence in place and yield swaps.
		based on: https://rosettacode.org/wiki/Sorting_algorithms/Cycle_sort#Python
	"""
    for cycle_start, item in enumerate(sequence):
        pos = cycle_start
        for item2 in sequence[cycle_start + 1:]:
            if item2 < item:
                pos += 1
        if pos == cycle_start:
            continue
        while item == sequence[pos]:
            pos += 1
        sequence[pos], item = item, sequence[pos]
        yield cycle_start, pos
        while pos != cycle_start:
            pos = cycle_start
            for item2 in sequence[cycle_start + 1:]:
                if item2 < item:
                    pos += 1
            while item == sequence[pos]:
                pos += 1
            sequence[pos], item = item, sequence[pos]
            if pos != cycle_start:
                yield cycle_start, pos
