News for hackers. Stuff that matters.
Re:Functools – The Power of Higher-Order Functions in Python by BurningFrog on Friday July 09, 2021 @12:10AM (#27780405)
It will take Python 10 more years to allow a flatten()...
Re:Functools – The Power of Higher-Order Functions in Python by joshuamorton on Friday July 09, 2021 @01:40AM (#27780760)
Do you need the recursive form? Because a single flatten is itertools.chain.from_iterable
Re:Functools – The Power of Higher-Order Functions in Python by nerdponx on Friday July 09, 2021 @02:06AM (#27780869)
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))
Re:Functools – The Power of Higher-Order Functions in Python by BurningFrog on Friday July 09, 2021 @10:21AM (#27783938)
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.

Re:Functools – The Power of Higher-Order Functions in Python by staticautomatic on Friday July 09, 2021 @12:30AM (#27780496)
more_itertools ftw
Re:Functools – The Power of Higher-Order Functions in Python by masklinn on Friday July 09, 2021 @12:43AM (#27780539)
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.