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()...
[ Parent
| on HN ]
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