add spread
This commit is contained in:
@ -32,8 +32,6 @@ def gcd(*args):
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
``` python
|
||||
gcd(8,36); # 4
|
||||
gcd(8,36) # 4
|
||||
```
|
||||
@ -33,8 +33,7 @@ def lcm(*args):
|
||||
```
|
||||
|
||||
|
||||
|
||||
``` python
|
||||
lcm(12, 7); # 84
|
||||
lcm([1, 3, 4], 5); # 60
|
||||
lcm(12, 7) # 84
|
||||
lcm([1, 3, 4], 5) # 60
|
||||
```
|
||||
20
snippets/spread.md
Normal file
20
snippets/spread.md
Normal file
@ -0,0 +1,20 @@
|
||||
### spread
|
||||
|
||||
Implements javascript's spread syntax as a function. Flattens the list(non-deep) and returns an array.
|
||||
|
||||
```python
|
||||
def spread(arg):
|
||||
ret = []
|
||||
for i in arg:
|
||||
if isinstance(i, list):
|
||||
ret.extend(i)
|
||||
else:
|
||||
ret.append(i)
|
||||
return ret
|
||||
|
||||
```
|
||||
|
||||
|
||||
```python
|
||||
spread([1,2,3,[4,5,6],[7],8,9]) # [1,2,3,4,5,6,7,8,9]
|
||||
```
|
||||
BIN
stopwatch.png
BIN
stopwatch.png
Binary file not shown.
|
Before Width: | Height: | Size: 98 KiB |
Reference in New Issue
Block a user