pythondata = "abracadabra$" buf = [] for i in range(len(data)): buf.append((data[i:], i)) buf.sort() for x in buf: print(x)