diff --git a/Week02/weighted_emin_ulguc.py b/Week02/weighted_emin_ulguc.py new file mode 100644 index 00000000..7af14424 --- /dev/null +++ b/Week02/weighted_emin_ulguc.py @@ -0,0 +1,9 @@ +import random + +def weighted_srs(data, n, weights, with_replacement=False): + if weights is not None: + return random.choices(data, weights=weights, k=n) + elif with_replacement: + return random.choices(data, weights=weights, k=n) + else: + return random.sample(data, n)