Created
January 21, 2022 22:50
-
-
Save malcolmgreaves/d996ab53242e9aacc10a797b25070a08 to your computer and use it in GitHub Desktop.
Re-sort any list given a list of new index positions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import TypeVar | |
from toolz import first, second | |
T = TypeVar('T') | |
def align(new_positions: List[int], items: List[T]) -> List[T]: | |
"""Re-sort any list given a list of new index positions. | |
""" | |
return list(map(second, sorted(list(zip(new_positions, items)), key=first))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment