0

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)

Jesse Downing
  • 355
  • 4
  • 14
  • Since most of the standard flattening idioms work fit on one line, I don't think we need a separate question. Plus, this is Python: we shouldn't care about cramming everything onto one line anyway. – DSM Jan 11 '16 at 03:27

1 Answers1

0

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']
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97