MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / alternative_list_arrange

Function alternative_list_arrange

other/alternative_list_arrange.py:1–30  ·  view source on GitHub ↗

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_arrang

(first_input_list: list, second_input_list: list)

Source from the content-addressed store, hash-verified

1def 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
33if __name__ == "__main__":

Callers 1

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected