min_n and max_n
This commit is contained in:
13
README.md
13
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.
|
||||
|
||||
@ -23,6 +23,7 @@ def spread(arg):
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
|
||||
@ -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]
|
||||
```
|
||||
@ -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]
|
||||
```
|
||||
Reference in New Issue
Block a user