Update u3/flatten_array.py

This commit is contained in:
Roman Dmytruk 2026-10-01 14:51:08 +00:00
parent c9ca31a83b
commit 354ffbcd8d

View File

@ -2,9 +2,9 @@ def flatten(iterable):
result = []
for item in iterable:
if isinstance(item, (list, tuple)):
# Якщо елемент є списком або кортежем — викликаємо flatten рекурсивно
# is the element is a list or a tuple, we call 'flatten' recursively /// Ak je prvok zoznamom alebo tupľom, voláme funkciu flatten rekurzívne
result.extend(flatten(item))
elif item is not None:
# Додаємо елемент лише якщо він не None
# pridame prvok len vtedy, ak nie je None /// add an element only if it is not None
result.append(item)
return result