remove_last_matching

emlib.misc.remove_last_matching(seq, func)[source]

Remove last element of seq matching the given condition, in place

Parameters:
  • seq (list[TypeVar(T)]) – the list to modify

  • func (Callable[[TypeVar(T)], bool]) – a function taking an element of seq, should return True if this is the element to remove

Return type:

Optional[TypeVar(T)]

Returns:

the removed element, or None if the condition was never met

Example

>>> a = [0, 1, 2, 3, 4, 5, 6]
>>> remove_last_matching(a, lambda item: item % 2 == 1)
>>> a
[0, 1, 2, 3, 4, 6]