Skip to content

Commit 331f10e

Browse files
authored
Merge pull request #107 from hakanmagat/patch-2
Create weighted_hakan_magat.py
2 parents 924b4a2 + 4646733 commit 331f10e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Week03/weighted_hakan_magat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import random #random
2+
3+
def weighted_srs(data, n, weights, with_replacement = False):
4+
if with_replacement == True or weights != None:
5+
randomlist = random.choices(data, k = n, weights = weights)
6+
else:
7+
randomlist = random.sample(data, n)
8+
return randomlist

0 commit comments

Comments
 (0)