#inputs s = "codeleet" indices = [4,5,6,7,0,2,1,3] #break the string into array of characters ['c', 'o', 'd', 'e', 'l', 'e', 'e', 't'] l = list(s) #initialize output array of the same length as the input string output = ['']*len(s) for i in range(0, len(indices)): #shuffle output[indices[i]] = s[i] #join the output array print("".join(output))