Skip to content

Commit

Permalink
ya ne eby?? sorry i forgot &&
Browse files Browse the repository at this point in the history
  • Loading branch information
fxrlxrn committed Aug 7, 2023
1 parent 50489a5 commit 319c7b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}
18 changes: 17 additions & 1 deletion pystd/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,20 @@ def choices(population, weights=None, *, cumulative_weights=None, k=1) -> list:


def sample(population, k, *, counts=None):
...
population = list(population)
if counts is None:
p1 = population.copy()
else:
p1 = list()
for i in range(len(population)):
p1.extend([population[i]] * counts[i])

if k > len(p1):
raise ValueError

ls = list()
for i in range(k):
b = choice(p1)
ls.append(b)
p1.remove(b)
return ls

0 comments on commit 319c7b9

Please sign in to comment.