fix deep_flatten
This commit is contained in:
23
README.md
23
README.md
@ -107,19 +107,13 @@ def spread(arg):
|
|||||||
ret.append(i)
|
ret.append(i)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def deep_flatten(arr):
|
def deep_flatten(arr):
|
||||||
result = []
|
result = []
|
||||||
result.extend(spread(list(map(lambda x : deep(x) if type(x) == list else x,arr))))
|
result.extend(
|
||||||
|
spread(list(map(lambda x: deep(x) if type(x) == list else x, arr))))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -335,16 +329,17 @@ def zip(*args, fillvalue=None):
|
|||||||
max_length = max([len(arr) for arr in args])
|
max_length = max([len(arr) for arr in args])
|
||||||
result = []
|
result = []
|
||||||
for i in range(max_length):
|
for i in range(max_length):
|
||||||
result.append([args[k][i] if i < len(args[k])
|
result.append([
|
||||||
else None for k in range(len(args))])
|
args[k][i] if i < len(args[k]) else None for k in range(len(args))
|
||||||
|
])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
zip(['a', 'b'], [1, 2], [True, False]); // [['a', 1, True], ['b', 2, False]]
|
zip(['a', 'b'], [1, 2], [True, False]) // [['a', 1, True], ['b', 2, False]]
|
||||||
zip(['a'], [1, 2], [True, False]); // [['a', 1, True], [None, 2, False]]
|
zip(['a'], [1, 2], [True, False]) // [['a', 1, True], [None, 2, False]]
|
||||||
zip(['a'], [1, 2], [True, False], fill_value = '_'); // [['a', 1, True], ['_', 2, False]]
|
zip(['a'], [1, 2], [True, False], fill_value = '_') // [['a', 1, True], ['_', 2, False]]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import autopep8
|
import autopep8
|
||||||
|
from yapf.yapflib.yapf_api import FormatCode
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
files = os.listdir('snippets')
|
files = os.listdir('snippets')
|
||||||
|
|||||||
@ -16,19 +16,13 @@ def spread(arg):
|
|||||||
ret.append(i)
|
ret.append(i)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def deep_flatten(arr):
|
def deep_flatten(arr):
|
||||||
result = []
|
result = []
|
||||||
result.extend(spread(list(map(lambda x : deep(x) if type(x) == list else x,arr))))
|
result.extend(
|
||||||
|
spread(list(map(lambda x: deep(x) if type(x) == list else x, arr))))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|||||||
@ -11,8 +11,9 @@ def zip(*args, fillvalue=None):
|
|||||||
max_length = max([len(arr) for arr in args])
|
max_length = max([len(arr) for arr in args])
|
||||||
result = []
|
result = []
|
||||||
for i in range(max_length):
|
for i in range(max_length):
|
||||||
result.append([args[k][i] if i < len(args[k])
|
result.append([
|
||||||
else None for k in range(len(args))])
|
args[k][i] if i < len(args[k]) else None for k in range(len(args))
|
||||||
|
])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user