diff options
| author | Karan Jayachandra <mail@karanjayachandra.com> | 2024-10-16 21:41:27 +0000 |
|---|---|---|
| committer | Karan Jayachandra <mail@karanjayachandra.com> | 2024-10-16 21:41:27 +0000 |
| commit | 36cc7d82a55cbd8167e1f52637dd1938497dd8cc (patch) | |
| tree | 096d2b629818f79674d22a14eff124f082449b6e /utilities.py | |
| parent | d18e5880b47fcdf6542bcb9502e8cf35a4276f05 (diff) | |
| parent | 9d25fd163d2b8ba8978747c1edc1fc0d2073f076 (diff) | |
Merge branch 'feature/db' into 'develop'
Full Functionality
See merge request KaranJayachandra/match_up!2
Diffstat (limited to 'utilities.py')
| -rw-r--r-- | utilities.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/utilities.py b/utilities.py new file mode 100644 index 0000000..1ad24b8 --- /dev/null +++ b/utilities.py @@ -0,0 +1,23 @@ +from typing import Tuple +from random import shuffle + + +def _shuffle_two_lists(a: list, b: list) -> Tuple[list, list]: + indices = list(range(len(a))) + shuffle(indices) + a = [a[index] for index in indices] + b = [b[index] for index in indices] + return a, b + + +def _pick_from_list_after_sorting_other(a: list, b: list[int]) -> list: + indices = [i[0] for i in sorted(enumerate(b), key=lambda x: x[1])] + return [a[index] for index in indices] + + +def sample_list(indices: list, cost: list[int], count: int = None) -> list: + if count is None: + count = len(indices) + indices, cost = _shuffle_two_lists(indices, cost) + indices = _pick_from_list_after_sorting_other(indices, cost)[:count] + return indices |
