diff --git a/snippets/median.md b/snippets/median.md index ddc003a06..2cfcb91bc 100644 --- a/snippets/median.md +++ b/snippets/median.md @@ -7,6 +7,8 @@ Finds the median of a list of numbers. Sort the numbers of the list using `list.sort()` and find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even. +[`statistics.median()`](https://docs.python.org/3/library/statistics.html#statistics.median) provides similar functionality to this snippet. + ```py def median(list): list.sort() diff --git a/snippets/sample.md b/snippets/sample.md index f280e61be..18eb6b786 100644 --- a/snippets/sample.md +++ b/snippets/sample.md @@ -7,6 +7,8 @@ Returns a random element from a list. Use `random.randint()` to generate a random number that corresponds to an index in the list, return the element at that index. +[`random.sample()`](https://docs.python.org/3/library/random.html#random.sample) provides similar functionality to this snippet. + ```py from random import randint diff --git a/snippets/shuffle.md b/snippets/shuffle.md index abbd2b3b6..d5ca0ba78 100644 --- a/snippets/shuffle.md +++ b/snippets/shuffle.md @@ -7,6 +7,8 @@ Randomizes the order of the values of an list, returning a new list. Uses the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) to reorder the elements of the list. +[`random.shuffle`](https://docs.python.org/3/library/random.html#random.shuffle) provides similar functionality to this snippet. + ```py from copy import deepcopy from random import randint diff --git a/snippets/split_lines.md b/snippets/split_lines.md index 80fe9c276..fdafdb0a0 100644 --- a/snippets/split_lines.md +++ b/snippets/split_lines.md @@ -7,6 +7,8 @@ Splits a multiline string into a list of lines. Use `s.split()` and `'\n'` to match line breaks and create a list. +[`str.splitlines()`](https://docs.python.org/3/library/stdtypes.html#str.splitlines) provides similar functionality to this snippet. + ```py def split_lines(s): return s.split('\n') diff --git a/snippets/zip.md b/snippets/zip.md index a9fb819d2..88d02c385 100644 --- a/snippets/zip.md +++ b/snippets/zip.md @@ -9,6 +9,8 @@ Use `max` combined with `list comprehension` to get the length of the longest li Loop for `max_length` times grouping elements. If lengths of `lists` vary, use `fill_value` (defaults to `None`). +[`zip()`](https://docs.python.org/3/library/functions.html#zip) and [`itertools.zip_longest()`](https://docs.python.org/3/library/itertools.html#itertools.zip_longest) provide similar functionality to this snippet. + ```py def zip(*args, fill_value=None): max_length = max([len(lst) for lst in args])