drop_right_while()
Creates a slice of `array` excluding elements dropped from the end. Elements are dropped until `predicate` returns falsey. The predicate is invoked with three arguments: (value, index, array).
Implementation
Args: array: List to process. predicate: Function invoked per iteration. Returns: Dropped list.
Example
drop_right_while([1, 2, 3, 4], lambda x: x >= 3)
Expected output: [1, 2]
Source Code
def drop_right_while(array: List[T], predicate: Callable[[T], bool]) -> List[T]:
for idx in range(len(array) - 1, -1, -1):
if not predicate(array[idx]):
return array[: idx + 1]
return []