-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move threshold parameters to subcontroller
Copy partition util from fastcs_odin
- Loading branch information
Showing
2 changed files
with
179 additions
and
51 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Callable, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def partition( | ||
elements: list[T], predicate: Callable[[T], bool] | ||
) -> tuple[list[T], list[T]]: | ||
"""Split a list of elements in two based on predicate. | ||
If the predicate returns ``True``, the element will be placed in the truthy list, | ||
if it does not, it will be placed in the falsy list. | ||
Args: | ||
elements: List of T | ||
predicate: Predicate to filter the list with | ||
Returns: | ||
(truthy, falsy) | ||
""" | ||
truthy: list[T] = [] | ||
falsy: list[T] = [] | ||
for parameter in elements: | ||
if predicate(parameter): | ||
truthy.append(parameter) | ||
else: | ||
falsy.append(parameter) | ||
|
||
return truthy, falsy |