update insertion_sort
This commit is contained in:
@ -1,20 +1,20 @@
|
||||
### 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).
|
||||
|
||||
Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` module to create a shallow clone of the list and sort it in ascending order. Use `[:n]` to get the specified number of elements. Omit the second argument, `n`, to get a one-element array
|
||||
|
||||
```python
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
def min_n(arr, n=1):
|
||||
numbers = deepcopy(arr)
|
||||
numbers.sort()
|
||||
return numbers[:n]
|
||||
```
|
||||
|
||||
```python
|
||||
min_n([1, 2, 3]) # [1]
|
||||
min_n([1, 2, 3], 2) # [1,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).
|
||||
|
||||
Use `list.sort()` combined with the `deepcopy` function from the inbuilt `copy` module to create a shallow clone of the list and sort it in ascending order. Use `[:n]` to get the specified number of elements. Omit the second argument, `n`, to get a one-element array
|
||||
|
||||
```python
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
def min_n(arr, n=1):
|
||||
numbers = deepcopy(arr)
|
||||
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