Update code in spread
This commit is contained in:
@ -11,13 +11,10 @@ Loop over elements, use `list.extend()` if the element is a list, `list.append()
|
||||
def spread(arg):
|
||||
ret = []
|
||||
for i in arg:
|
||||
if isinstance(i, list):
|
||||
ret.extend(i)
|
||||
else:
|
||||
ret.append(i)
|
||||
ret.extend(i) if isinstance(i, list) else ret.append(i)
|
||||
return ret
|
||||
```
|
||||
|
||||
```py
|
||||
spread([1,2,3,[4,5,6],[7],8,9]) # [1,2,3,4,5,6,7,8,9]
|
||||
```
|
||||
spread([1, 2, 3, [4, 5, 6], [7], 8, 9]) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user