travis_commit
This commit is contained in:
27
README.md
27
README.md
@ -70,6 +70,33 @@ count_vowels('foobar') # 3
|
||||
count_vowels('gym') # 0
|
||||
```
|
||||
|
||||
### deepFlatten
|
||||
|
||||
Deep flattens a list.
|
||||
|
||||
Use recursion. Use `list.extend()` with an empty array (`result`) and the spread function to flatten a list. Recursively flatten each element that is a list.
|
||||
|
||||
```python
|
||||
|
||||
def spread(arg):
|
||||
ret = []
|
||||
for i in arg:
|
||||
if isinstance(i, list):
|
||||
ret.extend(i)
|
||||
else:
|
||||
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))))
|
||||
return result
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
deep_flatten([1, [2], [[3], 4], 5]) # [1,2,3,4,5]
|
||||
```
|
||||
### gcd
|
||||
|
||||
Calculates the greatest common divisor between two or more numbers/lists.
|
||||
|
||||
@ -5,6 +5,7 @@ Deep flattens a list.
|
||||
Use recursion. Use `list.extend()` with an empty array (`result`) and the spread function to flatten a list. Recursively flatten each element that is a list.
|
||||
|
||||
```python
|
||||
|
||||
def spread(arg):
|
||||
ret = []
|
||||
for i in arg:
|
||||
@ -18,6 +19,7 @@ def spread(arg):
|
||||
result = []
|
||||
result.extend(spread(list(map(lambda x : deep(x) if type(x) == list else x,arr))))
|
||||
return result
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
|
||||
Reference in New Issue
Block a user