add chunk
This commit is contained in:
@ -4,9 +4,9 @@
|
||||
|
||||
Here's what you can do to help:
|
||||
|
||||
- [Open issues](https://github.com/kriadmin/30-seconds-of-code-python/issues/new) for things you want to see added or modified.
|
||||
- Be part of the discussion by helping out with [existing issues](https://github.com/kriadmin/30-seconds-of-code-python/issues) or talking on our [gitter channel](https://gitter.im/30-seconds-of-code-python/Lobby).
|
||||
- Submit [pull requests](https://github.com/kriadmin/30-seconds-of-code-python/pulls) with snippets you have created (see below for guidelines).
|
||||
- [Open issues](https://github.com/kriadmin/30-seconds-of-python-code/issues/new) for things you want to see added or modified.
|
||||
- Be part of the discussion by helping out with [existing issues](https://github.com/kriadmin/30-seconds-of-python-code/issues) or talking on our [gitter channel](https://gitter.im/30-seconds-of-python-code/Lobby).
|
||||
- Submit [pull requests](https://github.com/kriadmin/30-seconds-of-python-code/pulls) with snippets you have created (see below for guidelines).
|
||||
- Fix typos in existing snippets, improve snippet descriptions and explanations or provide better examples.
|
||||
|
||||
### Snippet submission and Pull request guidelines
|
||||
@ -24,7 +24,7 @@ Here's what you can do to help:
|
||||
- **Snippets _CAN NOT_ use any external modules**. Only the modules and function inbuilt in `python 3.6` shall be used.
|
||||
- **Snippet code** must be enclosed inside ` ```python ` and ` ``` `.
|
||||
- Remember to start your snippet's code on a new line below the opening backticks.
|
||||
- Please follow [This Style Guide](https://www.python.org/dev/peps/pep-0008/) for your code.
|
||||
- Please follow [This Style Guide](https://www.python.org/dev/peps/pep-0008/) for your code.(Though it doen't matter much as your code is automatically prettified)
|
||||
- Try to keep your snippets' code short and to the point. Use modern techniques and features. Make sure to test your code before submitting.
|
||||
- All snippets must be followed by one (more if necessary) test case after the code, in a new block enclosed inside ` ```python ` and ` ``` `. The syntax for this is `myFunction('testInput') # 'testOutput'`. Use multiline examples only if necessary.
|
||||
- Try to make your function name unique, so that it does not conflict with existing snippets.
|
||||
|
||||
25
README.md
25
README.md
@ -1,10 +1,31 @@
|
||||

|
||||
|
||||
# 30-seconds-of-code-python
|
||||
# 30-seconds-of-python-code
|
||||
Python implementation of 30-seconds-of-code.
|
||||
|
||||
**Note**:- This is in no way affiliated with the original [30-seconds-of-code](https://github.com/Chalarangelo/30-seconds-of-code/)
|
||||
**Note**:- This is in no way affiliated with the original [30-seconds-of-code](https://github.com/Chalarangelo/30-seconds-of-code/).
|
||||
|
||||
|
||||
### chunk
|
||||
|
||||
Chunks an array into smaller arrays of a specified size.
|
||||
|
||||
Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`
|
||||
|
||||
```python
|
||||
from math import ceil
|
||||
|
||||
|
||||
def chunk(arr, size):
|
||||
return list(
|
||||
map(lambda x: arr[x * size:x * size + size],
|
||||
list(range(0, ceil(len(arr) / size)))))
|
||||
|
||||
```
|
||||
|
||||
``` python
|
||||
chunk([1,2,3,4,5],2) # [[1,2],[3,4],5]
|
||||
```
|
||||
### gcd
|
||||
|
||||
Calculates the greatest common divisor between two or more numbers/arrays.
|
||||
|
||||
15
snippet_template.md
Normal file
15
snippet_template.md
Normal file
@ -0,0 +1,15 @@
|
||||
### functionName
|
||||
|
||||
Describe briefly what the function does
|
||||
|
||||
Explain your method and the functions used.
|
||||
|
||||
``` python
|
||||
def functionName(args):
|
||||
# code
|
||||
return 0
|
||||
```
|
||||
|
||||
``` python
|
||||
functionName(val) # result
|
||||
```
|
||||
20
snippets/chunk.md
Normal file
20
snippets/chunk.md
Normal file
@ -0,0 +1,20 @@
|
||||
### chunk
|
||||
|
||||
Chunks an array into smaller arrays of a specified size.
|
||||
|
||||
Uses `range` to create a list of desired size. Then use `map` on this list and fill it with splices of `arr`
|
||||
|
||||
```python
|
||||
from math import ceil
|
||||
|
||||
|
||||
def chunk(arr, size):
|
||||
return list(
|
||||
map(lambda x: arr[x * size:x * size + size],
|
||||
list(range(0, ceil(len(arr) / size)))))
|
||||
|
||||
```
|
||||
|
||||
``` python
|
||||
chunk([1,2,3,4,5],2) # [[1,2],[3,4],5]
|
||||
```
|
||||
Reference in New Issue
Block a user