Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

It will take Python 10 more years to allow a flatten()...


Do you need the recursive form? Because a single flatten is itertools.chain.from_iterable


I 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))


I 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.


more_itertools ftw


10 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: