1rearrange elements in a python list based on given array of indices, but not of the same size of the arrayrearrange elements in a python list based on given array of indices, but not of the same size of the array# rearrange elements in a python list based on given array of indices, but not of the same size of the array

0

1 answers

This should do the trick

```
cipher = ['t', 'h', 'i', 's', 'w', 'o', 'r', 'k', 'i', 'n', 'g']
index = [1, 2, 0]
splitCipher = [cipher[i:i+len(index)] for i in range(0,len(cipher),len(index))]
newCipher = []
for group in splitCipher:
for i in range(len(index)):
try:
newCipher.append(group[index[i]])
except:
pass
print(newCipher)
```

Source: link