For example, I have a list of lists:
[[['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']]]
I want to remove inner one to be like this
[['--w', 'ww-', 'bbb'], ['w--', '-ww', 'bbb']]
How can I do this?
For example, I have a list of lists:
[[['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']]]
I want to remove inner one to be like this
[['--w', 'ww-', 'bbb'], ['w--', '-ww', 'bbb']]
How can I do this?
If this is just for the purposes of printing, you can do:
list_o_lists_o_lists = [[['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']]]
print(*list_o_lists_o_lists, sep=", ")
which unpacks the outer list
into its two inner list
s as sequential arguments to print
, which prints each separately, while sep=", "
tells print
to place a comma and space between each of them, getting the display you want, but making no change to the data structure.
But otherwise, what you want isn't possible as stated; removing the outer brackets leaves you with two elements that need to be stored in something. The literal with those brackets removed is a tuple
:
[['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']]
but the repr
of a tuple
includes parentheses, so you'd just be replacing the outer brackets with parens if you printed it without special formatting effort:
>>> [['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']]
([['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']])
Your description doesn't match your desired output. Your desired output has the inner brackets removed, not the outer ones. To remove the inner brackets, you can do
[[item[0] for item in inner_list] for inner_list in outer_list]
Try this
[[j[0] for j in i] for i in [[['--w'], ['ww-'], ['bbb']], [['w--'], ['-ww'], ['bbb']]]]
Output:
[['--w', 'ww-', 'bbb'], ['w--', '-ww', 'bbb']]