Skip to content

Added alternative_list_arrange method #4631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions other/alternative_list_arrange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def alternative_list_arrange(first_input_list: list, second_input_list: list) -> list:
"""
The method arranges two lists as one list in alternative forms of the list elements.
:param first_input_list:
:param second_input_list:
:return: List
>>> alternative_list_arrange([1, 2, 3, 4, 5], ["A", "B", "C"])
[1, 'A', 2, 'B', 3, 'C', 4, 5]
>>> alternative_list_arrange(["A", "B", "C"], [1, 2, 3, 4, 5])
['A', 1, 'B', 2, 'C', 3, 4, 5]
>>> alternative_list_arrange(["X", "Y", "Z"], [9, 8, 7, 6])
['X', 9, 'Y', 8, 'Z', 7, 6]
>>> alternative_list_arrange([1, 2, 3, 4, 5], [])
[1, 2, 3, 4, 5]
"""
first_input_list_length: int = len(first_input_list)
second_input_list_length: int = len(second_input_list)
abs_length: int = (
first_input_list_length
if first_input_list_length > second_input_list_length
else second_input_list_length
)
output_result_list: list = []
for char_count in range(abs_length):
if char_count < first_input_list_length:
output_result_list.append(first_input_list[char_count])
if char_count < second_input_list_length:
output_result_list.append(second_input_list[char_count])

return output_result_list


if __name__ == "__main__":
print(alternative_list_arrange(["A", "B", "C"], [1, 2, 3, 4, 5]), end=" ")