travis_commit

This commit is contained in:
Rohit Tanwar
2018-01-16 15:05:34 +00:00
parent 45b9722566
commit a23c7be7e5
2 changed files with 30 additions and 1 deletions

View File

@ -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.

View File

@ -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