Combine a 2D array into 1D without numpy

Question:

The result of a list comprehension:

[['a', 'b', 'c'], ['ab', 'ac', 'bc'], ['abc']]

The challenge is to convert this into a single list, on one line, importing only itertools (if it helps)

Asked By: Jesse Downing

||

Answers:

The easy way is with itertools.chain.from_iterable:

>>> import itertools
>>> list(itertools.chain.from_iterable([['a', 'b', 'c'], ['ab', 'ac', 'bc'], ['abc']]))
['a', 'b', 'c', 'ab', 'ac', 'bc', 'abc']
Answered By: TigerhawkT3
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.