diff --git a/README.md b/README.md index 10c854f74..c211d25f0 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ def spread(arg): + ``` ```python @@ -193,6 +194,7 @@ Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` ```python + from copy import deepcopy @@ -203,6 +205,11 @@ def max_n(arr, n=1): return numbers[:n] ``` + +```python +max_n([1, 2, 3]) # [3] +max_n([1, 2, 3], 2) # [3,2] +``` ### min_n Returns the `n` minimum elements from the provided list. If `n` is greater than or equal to the provided list's length, then return the original list(sorted in ascending order). @@ -211,6 +218,7 @@ Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` ```python + from copy import deepcopy @@ -220,6 +228,11 @@ def min_n(arr, n=1): return numbers[:n] ``` + +```python +min_n([1, 2, 3]) # [1] +min_n([1, 2, 3], 2) # [1,2] +``` ### spread Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an list. diff --git a/snippets/deep_flatten.md b/snippets/deep_flatten.md index 49778a251..a683fd4b0 100644 --- a/snippets/deep_flatten.md +++ b/snippets/deep_flatten.md @@ -23,6 +23,7 @@ def spread(arg): + ``` ```python diff --git a/snippets/max_n.md b/snippets/max_n.md index e34b60a2e..9fdb99b34 100644 --- a/snippets/max_n.md +++ b/snippets/max_n.md @@ -6,6 +6,7 @@ Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` ```python + from copy import deepcopy @@ -15,4 +16,9 @@ def max_n(arr, n=1): numbers.reverse() return numbers[:n] +``` + +```python +max_n([1, 2, 3]) # [3] +max_n([1, 2, 3], 2) # [3,2] ``` \ No newline at end of file diff --git a/snippets/min_n.md b/snippets/min_n.md index 3298a46f8..e854b06aa 100644 --- a/snippets/min_n.md +++ b/snippets/min_n.md @@ -6,6 +6,7 @@ Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` ```python + from copy import deepcopy @@ -14,4 +15,9 @@ def min_n(arr, n=1): numbers.sort() return numbers[:n] +``` + +```python +min_n([1, 2, 3]) # [1] +min_n([1, 2, 3], 2) # [1,2] ``` \ No newline at end of file