sort_by()
Sort an array by a function or key.
Implementation
Args: array: The array to sort key_func: A function that returns a comparable value Returns: A new sorted array
Example
sort_by([1, 2, 3], lambda x: -x)
Expected output: [3, 2, 1]
Source Code
def sort_by(array: List[T], key_func: Callable[[T], Any]) -> List[T]:
return sorted(array, key=key_func)