I want to concatenate 2D lists to the end of a list_log, as follows:
list_log = []
list1 = [[0.0], [1.7], [8.4], [20.1], [29.3], [41.8], [74.1], [61.9]]
list2 = [[1.0], [3.6], [13.5], [31.5], [50.3], [64.4], [93.3], [113.8]]
list_log.append(list1)
list_log.append(list2)
Desired result:
list_log = [[0.0, 1.0], [1.7, 3.6], [8.4, 13.5], [20.1, 31.5], [29.3, 50.3], [41.8, 64.4], [74.1, 93.3], [61.9, 113.8]]
Actual result: list_log = [[[0.0], [1.7], [8.4], [20.1], [29.3], [41.8], [74.1], [61.9]], [[1.0], [3.6], [13.5], [31.5], [50.3], [64.4], [93.3], [113.8]]]
I've also tried getting this result using list comprehension, as follows:
list_log2 = [[[i, j] for i in list1[c] for j in list2[c]] for c in range(8)]
But this gives the following result: list_log2 = [[[0.0, 1.0]], [[1.7, 3.6]], [[8.4, 13.5]], [[20.1, 31.5]], [[29.3, 50.3]], [[41.8, 64.4]], [[74.1, 93.3]], [[61.9, 113.8]]]
, so with too many brackets.
Also, the example above uses only two lists, but in reality I have thousands of these lists coming in one after the other, and which I need to append to the end of the list_log one-by-one. Because of this I'm reluctant to use list comprehension as shown above, because this basically re-generates the entire log_list2 each time I append a new list, which isn't very efficient. That's why I'm trying to make this happen with .append() instead, as adding one element to the end of a list is computationally much less intensive than re-creating the entire log each time.
So ideally I'd like to make this work with .append() (or similar stuff like .extend()), but I'm open to all suggestions. Thanks in advance!