9 ms·
Do you need the recursive form? Because a single flatten is itertools.chain.from_iterable
by joshuamorton 5y ago
Do you need the recursive form? Because a single flatten is itertools.chain.from_iterable
- nerdponx 5y agoI have written this in serious code before, and I don't regret it: from itertools import chain flatten = chain.from_iterable def lflatten(x): return list(flatten(x)) def sflatten(x): return set(flatten(x))
- BurningFrog 5y agoI know it exists, but the universally known name is 80% of the utility of having a standard flatten() function. I could tolerate a slightly different name, but `itertools.chain.from_iterable` is absurd to me.