avp26/ u3/flatten_array.py

10 lines
443 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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