|
| 1 | +def alternative_list_arrange(first_input_list: list, second_input_list: list) -> list: |
| 2 | + """ |
| 3 | + The method arranges two lists as one list in alternative forms of the list elements. |
| 4 | + :param first_input_list: |
| 5 | + :param second_input_list: |
| 6 | + :return: List |
| 7 | + >>> alternative_list_arrange([1, 2, 3, 4, 5], ["A", "B", "C"]) |
| 8 | + [1, 'A', 2, 'B', 3, 'C', 4, 5] |
| 9 | + >>> alternative_list_arrange(["A", "B", "C"], [1, 2, 3, 4, 5]) |
| 10 | + ['A', 1, 'B', 2, 'C', 3, 4, 5] |
| 11 | + >>> alternative_list_arrange(["X", "Y", "Z"], [9, 8, 7, 6]) |
| 12 | + ['X', 9, 'Y', 8, 'Z', 7, 6] |
| 13 | + >>> alternative_list_arrange([1, 2, 3, 4, 5], []) |
| 14 | + [1, 2, 3, 4, 5] |
| 15 | + """ |
| 16 | + first_input_list_length: int = len(first_input_list) |
| 17 | + second_input_list_length: int = len(second_input_list) |
| 18 | + abs_length: int = ( |
| 19 | + first_input_list_length |
| 20 | + if first_input_list_length > second_input_list_length |
| 21 | + else second_input_list_length |
| 22 | + ) |
| 23 | + output_result_list: list = [] |
| 24 | + for char_count in range(abs_length): |
| 25 | + if char_count < first_input_list_length: |
| 26 | + output_result_list.append(first_input_list[char_count]) |
| 27 | + if char_count < second_input_list_length: |
| 28 | + output_result_list.append(second_input_list[char_count]) |
| 29 | + |
| 30 | + return output_result_list |
| 31 | + |
| 32 | + |
| 33 | +if __name__ == "__main__": |
| 34 | + print(alternative_list_arrange(["A", "B", "C"], [1, 2, 3, 4, 5]), end=" ") |
0 commit comments