I have a server that accesses and gets data in the format of a multidimensional array so the end result is:
[
[
[n1t1:1, n1s1:2, n1o1:5],
[n1t2:3, n1s2:8, n1o2:9]
],
[
[n2t1:9, n2s1:3, n2o1:2],
[n2t2:5, n2s2:1, n2o2:7]
],
[
[n3t1:4, n3s1:9, n3o1:2],
[n3t2:7, n3s2:1, n3o2:5]
]
]
I need to go through that array, access only s1 values and store them into a new array that will be returned as a result.
Option 1:
result = []
parent_enum = 0
while len(array) > parent_enum:
child_enum = 0
result.append([])
while len(child_enum) > array_num:
result[parent_enum].append(array[parent_enum][child_enum][1])
child_enum += 1
parent_enum += 1
Option 2:
result = [[] for i in range(len(array))]
parent_enum = 0
while len(array[0]) > parent_enum:
child_enum = 0
while len(array) > child_enum:
result[child_enum].append(array[child_enum][parent_enum][1])
child_enum += 1
parent_enum += 1
Is there a difference and if so, which way would be more efficient and fast? Considering the size of a 2nd dimension is up to 20 and 3rd dimension is up to 500