I saw two versions of the same code and wanted to know which one is efficiently better and which one is more frequently used in python.
output_list = [0 for _ in range(output_length)]
k=0
for i in range(input_length):
output_list[k] = input[i]
k += 1
And the second method is initializing a list with an empty list and appending item one by one. In C++ I think the former method will be method if you already know your output length. Does it matter for python stylistically?
output_list = []
for i in range(input_length):
output.append(input[i])
This is the not the actual problem I was concerned about but the problem was of the merge problem in merge sort where you have an auxiliary output array whose size will be the sum of the two halves. But I just gave a simple example above.
output_list = list(input_list). Why move stuff around manually if there's a builtin for that?