I have the following list structure:
the_given_list = [[[1],[2],[3]],[[1],[2],[3]]]
Indeed len(the_given_list) returns 2.
I need to make the following list:
the_given_list = [[1,2,3],[1,2,3]]
How to do it?
I have the following list structure:
the_given_list = [[[1],[2],[3]],[[1],[2],[3]]]
Indeed len(the_given_list) returns 2.
I need to make the following list:
the_given_list = [[1,2,3],[1,2,3]]
How to do it?
 
    
    [sum(x, []) for x in the_given_list]
Flatten the first-order element in the_given_list.
the_given_list = [sum(x, []) for x in the_given_list]
print(the_given_list)
 
    
    To explain the above answer https://stackoverflow.com/a/57369395/1465553, this list
[[[1],[2],[3]],[[1],[2],[3]]]
can be seen as
[list1, list2]
and,
>> sum([[1],[2],[3]], [])
[1,2,3]
>>> sum([[1],[2],[3]], [5])
[5, 1, 2, 3]
Since the second argument to method sum defaults to 0, we need to explicitly pass empty list [] to it to overcome type mismatch (between int and list). 
 
    
    Use itertools.chain
In [15]: from itertools import chain                                                                                                                                                                        
In [16]: [list(chain(*i)) for i in the_given_list]                                                                                                                                                          
Out[16]: [[1, 2, 3], [1, 2, 3]]
 
    
    Another solution:
the_given_list = [[[1],[2],[3]],[[1],[2],[3]]]
print([[j for sub in i for j in sub] for i in the_given_list])
Gives me:
[[1, 2, 3], [1, 2, 3]]
Check the original answer on list flattening:
