return list(sorted(a, key=lambda x: sortkeys[x['id']]))
a = [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}, {'id': 3, 'name':
    'baz'}]
b = [2, 1, 3]
print(sort_dict_by_list(a, b))
Python, sort a list of dicts by an arbitrary order