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