blob: 8aadfd2d738828efdcb560b749d18fbc203cb195 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
from time import time
from typing import Tuple
from random import shuffle
from dataclasses import dataclass
SECS_IN_MIN = 60
DEFAULT_TIMER = 12.0
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
|