4 ms·
It will take Python 10 more years to allow a flatten()...
by BurningFrog 5y ago
It will take Python 10 more years to allow a flatten()...
- staticautomatic 5y agomore_itertools ftw
- masklinn 5y ago10 years is very optimistic: flatten has little use without a functional pipeline (something like clojure’s threading macro) as in other contexts it’s a trivial comprehension.
- joshuamorton 5y agoDo 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.