I have a list of objects where objects can be lists or scalars. I want an flattened list with only scalars. Eg:
L = [35,53,[525,6743],64,63,[743,754,757]] ou
Here's a oneliner, based on the question you've mentioned:
list(itertools.chain(*((sl if isinstance(sl, list) else [sl]) for sl in l)))
UPDATE: And a fully iterator-based version:
from itertools import imap, chain list(chain.from_iterable(imap(lambda x: x if isinstance(x, list) else [x], l)))