We need a procedure that, with the input number N, created N separate arrays.
2 answers
To create N new lists:
lists = [[] for _ in range(N)] If the created objects are immutable, for example strings, then the syntax can be used more concisely:
strings = ["abc"] * N In this way, a list is created that is referenced N times to the same line. Therefore, this syntax with mutable objects such as a list should not be followed.
|
Is something needed?
def create_arr(n): main_list = [] for i in range(n): l_list = [] main_list.append(l_list) return main_list mylist = create_arr(5) (mylist[0].append(10)) print(mylist) |