Add u3/flatten_array.py
This commit is contained in:
parent
a62a61ecc8
commit
c9ca31a83b
10
u3/flatten_array.py
Normal file
10
u3/flatten_array.py
Normal file
@ -0,0 +1,10 @@
|
||||
def flatten(iterable):
|
||||
result = []
|
||||
for item in iterable:
|
||||
if isinstance(item, (list, tuple)):
|
||||
# Якщо елемент є списком або кортежем — викликаємо flatten рекурсивно
|
||||
result.extend(flatten(item))
|
||||
elif item is not None:
|
||||
# Додаємо елемент лише якщо він не None
|
||||
result.append(item)
|
||||
return result
|
||||
Loading…
Reference in New Issue
Block a user