moses¶
- emlib.misc.moses(pred, seq)[source]¶
Divides seq into two lists: filter(pred, seq), filter(not pred, seq)
- Parameters:
pred (
Callable[[TypeVar(T)],bool]) – a function predicateseq (
Iterable[TypeVar(T)]) – the seq. to divide
- Return type:
tuple[list[TypeVar(T)],list[TypeVar(T)]]- Returns:
a tuple
(true_elements, false_elements), where true_elements contains the items in seq for which pred evaluates to true, and false_elements contains the rest
Example:
>>> moses(lambda x:x > 5, range(10)) ([6, 7, 8, 9], [0, 1, 2, 3, 4, 5])