An ordering question

andrew cooke andrew at acooke.org
Fri Mar 13 14:37:55 EDT 2009


MRAB wrote:
>  >>> a = [(4, 1), (7, 3), (3, 2), (2, 4)]
>  >>> b = [2, 4, 1, 3]
>  >>> d = dict((v, k) for k, v in a)
>  >>> c = [(d[s], s) for s in b]
>  >>> c
> [(3, 2), (2, 4), (4, 1), (7, 3)]

ah, that is more efficient than the suggestions i posted.

andrew





More information about the Python-list mailing list