Message348447
Possible implementation:
from itertools import islice as _islice
def reservoir_sample(self, population, k):
if k < 0:
raise ValueError("Sample is negative")
it = iter(population)
result = list(_islice(it, k))
if len(result) < k:
raise ValueError("Sample larger than population")
self.shuffle(result)
randbelow = self._randbelow
for i, x in enumerate(it, k+1):
j = randbelow(i)
if j < k:
result[j] = x
return result |
|
Date |
User |
Action |
Args |
2019-07-25 17:50:06 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, mark.dickinson, thomasahle |
2019-07-25 17:50:06 | serhiy.storchaka | set | messageid: <1564077006.47.0.456295959046.issue37682@roundup.psfhosted.org> |
2019-07-25 17:50:06 | serhiy.storchaka | link | issue37682 messages |
2019-07-25 17:50:06 | serhiy.storchaka | create | |
|