diff --git a/Week01/info_caner_gundas.py b/Week01/info_caner_gundas.py new file mode 100644 index 00000000..25f3c08f --- /dev/null +++ b/Week01/info_caner_gundas.py @@ -0,0 +1,2 @@ +student_id = "230316044" +full_name = "Caner Gündaş" diff --git a/Week02/weighted_caner_gundas.py b/Week02/weighted_caner_gundas.py new file mode 100644 index 00000000..d347ee55 --- /dev/null +++ b/Week02/weighted_caner_gundas.py @@ -0,0 +1,12 @@ +import random + + + +def weighted_srs(data, n, weights, with_replacement): + if with_replacement: return random.choices(data, weights=weights, k=n) + res, d, w = [], list(data), list(weights) + for _ in range(n): + idx = random.choices(range(len(d)), weights=w)[0] + res.append(d.pop(idx)) + w.pop(idx) + return res