I have a dictionary
mydict = {'jon': 12, 'alex': 17, 'jane': 13}
and I want to create a np.array which contains the values 12, 17, 13, but sorted by another array
sortby = np.array(['jon', 'jane', 'alex'])
which should yield the output as
sorted_array = np.array([12, 13, 17])
Any approaches that are more efficient than looping through the sortby array like below?
sorted_array = []
for vals in sortby:
sorted_array.append(mydict[vals])
return np.array(sorted_array)