I have the following array:
array = [['[email protected]'], ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']]
How can I get the result out of this:
'[email protected]'
'[email protected]'
'[email protected]'
'[email protected]'
'[email protected]'
'[email protected]'
You don't exactly have an array, more like a list of lists. The most classic iterative way would be to do something like this:
We loop through each list within
array
and then each element of these lists.Another very compact way, which is basically similar to the previous one, is to use "list comprehension"
In this case, what we achieve is a "flat" list with all the elements, and then we concatenate all of these into a newline-separated string.
You can do for example:
or what would be the same:
you can do it like this: