Add u3/flatten_array.py

This commit is contained in:
Roman Dmytruk 2026-10-01 14:47:05 +00:00
parent a62a61ecc8
commit c9ca31a83b

10
u3/flatten_array.py Normal file
View 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