You could create a dict and pass its get method as key parameter in sorted
>>> words = ['jack', 'steve', 'john', 'mary']
>>> pos = [0, 12, 3, 5]
>>> sorted(words, key=dict(zip(words, pos)).get)
['jack', 'john', 'mary', 'steve']
You could create the dict
beforehand to make it more meaningful:
>>> word_pos = dict(zip(words, pos))
>>> sorted(words, key=word_pos.get)
['jack', 'john', 'mary', 'steve']
Another, slightly arcane way would be to use an iterator
object and call the next function on it. But it may be a little confusing.
>>> words = ['jack', 'steve', 'john', 'mary']
>>> pos = [0, 12, 3, 5]
>>> it = iter(pos)
>>> sorted(words, key=lambda _: next(it))
['jack', 'john', 'mary', 'steve']