How can I transform
list = [[68.0], [79.0], [6.0]], ... [[176.0], [120.0], [182.0]]
into
result = [68.0, 79.0, 6.0, 8.0], ... [176.0, 120.0, 182.0]
If I've correctly understood what input_lists should actually look like, then I think what you're after is creating a dict so that dict[n] is your nth list. eg: the following code:
input_lists = [[[68.0], [79.0], [6.0], [8.0], [61.0], [88.0], [59.0], [91.0]],
[[10.0], [11.0], [9.0], [120.0], [92.0], [12.0], [8.0], [13.0]],
[[17.0], [18.0], [13.0], [14.0], [12.0], [176.0], [120.0], [182.0]]]
lists = {i:[el[0] for el in v] for i, v in enumerate(input_lists, start=1)}
# {1: [68.0, 79.0, 6.0, 8.0, 61.0, 88.0, 59.0, 91.0], 2: [10.0, 11.0, 9.0, 120.0, 92.0, 12.0, 8.0, 13.0], 3: [17.0, 18.0, 13.0, 14.0, 12.0, 176.0, 120.0, 182.0]}
z = []
for x in list:
for i in x:
z.append(i)
Am I missing something or a simple list comprehension would do? And also list is a keyword in python PLEASE DO NOT name your variables which create conflict with python keywords. It will bite you in places you cant imagine.
>>> mylist = [[68.0], [79.0], [6.0], [8.0], [61.0], [88.0], [59.0], [91.0]]
>>> [i[0] for i in mylist]
[68.0, 79.0, 6.0, 8.0, 61.0, 88.0, 59.0, 91.0] #this can be assigned to a new list var mylist1
UPDATE: Based on what lbe said, changing the approach -
>>> mylist =[[[68.0], [79.0], [6.0], [8.0], [61.0], [88.0], [59.0], [91.0]],
... [[10.0], [11.0], [9.0], [120.0], [92.0], [12.0], [8.0], [13.0]],
... [[17.0], [18.0], [13.0], [14.0], [12.0], [176.0], [120.0], [182.0]]]
>>> [i[0] for i in reduce(lambda x, y: x+y, mylist)]
[68.0, 79.0, 6.0, 8.0, 61.0, 88.0, 59.0, 91.0, 10.0, 11.0, 9.0, 120.0, 92.0, 12.0, 8.0, 13.0, 17.0, 18.0, 13.0, 14.0, 12.0, 176.0, 120.0, 182.0]
First, the code above is invalid syntax. You need surrounding brackets or something similar.
list =[[[68.0], [79.0], [6.0], [8.0], [61.0], [88.0], [59.0], [91.0]],
[[10.0], [11.0], [9.0], [120.0], [92.0], [12.0], [8.0], [13.0]],
[[17.0], [18.0], [13.0], [14.0], [12.0], [176.0], [120.0], [182.0]]]
Then list[0], list[1], etc. refer to the sub-lists.
list =[[68.0], [79.0], [6.0], [8.0], [61.0], [88.0], [59.0], [91.0],
[10.0], [11.0], [9.0], [120.0], [92.0], [12.0], [8.0], [13.0],
[17.0], [18.0], [13.0], [14.0], [12.0], [176.0], [120.0], [182.0]]
That is, you want chunks of a long list. Then, just use slice syntax, ie, list[0:2] would be [[68.0], [79.0], [6.0]].
Assuming your data looks like it does in @JonClements answer, here's another approach using list comprehension.
[reduce(lambda x, y: x + y, l) for l in input_lists]
# [[68.0, 79.0, 6.0, 8.0, 61.0, 88.0, 59.0, 91.0],
# [10.0, 11.0, 9.0, 120.0, 92.0, 12.0, 8.0, 13.0],
# [17.0, 18.0, 13.0, 14.0, 12.0, 176.0, 120.0, 182.0]]
input_lists[0] returns (not a horizontal list as I provided above): 68.0 10.0 17.0
list1 = [68.0, 79.0, 6.0, 8.0, 61.0, 88.0, 59.0, 91.0]