Skip to content

Instantly share code, notes, and snippets.

@les-peters
Created October 19, 2021 19:04
Show Gist options
  • Select an option

  • Save les-peters/12f2ca633bcf87f5baa24be606b2d235 to your computer and use it in GitHub Desktop.

Select an option

Save les-peters/12f2ca633bcf87f5baa24be606b2d235 to your computer and use it in GitHub Desktop.
Reorder
question = """
Given an array of objects A, and an array of indexes B, reorder the objects in array A with the given indexes in array B.
Example:
let a = [C, D, E, F, G, H];
let b = [3, 0, 4, 1, 2, 5];
$ reorder(a, b) // a is now [D, F, G, C, E, H]
"""
def reorder(a,b):
e = [''] * len(a)
for i in range(0,len(a)):
e[b[i]] = a[i]
return e
a = ['C', 'D', 'E', 'F', 'G', 'H']
b = [3, 0, 4, 1, 2, 5]
print(reorder(a, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment