Skip to content

Commit

Permalink
Flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 10, 2024
1 parent 37d48ff commit a1ba91c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions kyu_5/flatten/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Flatten."""
16 changes: 11 additions & 5 deletions kyu_5/flatten/flatten.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> flatten()
Solution for -> flatten().
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def flatten(*args) -> list:
"""
Flatten function.
The method takes in any number of arguments
and flattens them into a single array. If any
of the arguments passed in are an array then
Expand All @@ -26,13 +29,16 @@ def flatten(*args) -> list:

def unpack(data, collection: list):
"""
Helper method. Unpack data until its not list or a tuple.
Unpack helper method.
Unpack data until its not list or a tuple.
:param data:
:param collection:
:return:
"""
if not isinstance(data, list) and not isinstance(data, tuple):
collection.append(data)
else:
if isinstance(data, (list, tuple)):
for d in data:
unpack(d, collection)
else:
collection.append(data)

Check notice on line 44 in kyu_5/flatten/flatten.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_5/flatten/flatten.py#L44

Trailing newlines (trailing-newlines)

Check notice on line 44 in kyu_5/flatten/flatten.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

kyu_5/flatten/flatten.py#L44

Trailing newlines
9 changes: 5 additions & 4 deletions kyu_5/flatten/test_flatten.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Solution for -> flatten()
Solution for -> flatten().
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -26,12 +27,12 @@
name='Source/Kata')
# pylint: enable-msg=R0801
class FlattenTestCase(unittest.TestCase):
"""
Testing flatten function
"""
"""Testing flatten function."""

def test_flatten(self):
"""
Testing flatten function with various test data.
For this exercise you will create a global flatten method.
The method takes in any number of arguments and flattens
them into a single array. If any of the arguments passed in
Expand Down

0 comments on commit a1ba91c

Please sign in to comment.