3 ms·
Here was one example I encountered a while back: https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists https://stackoverflow.c
by tanin 7y ago
Here was one example I encountered a while back: https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists https://stackoverflow.com/questions/952914/how-to-make-a-fla...
In Python, it's `import itertools` and `list(itertools.chain.from_iterable(list2d))` or `[item for sublist in list2d for item in sublist]`. In Scala, it is `list2d.flatten`.
In fact, Python is against making a richer stdlib in general.
"It has been discussed ad nauseam on comp.lang.python. People seem to enjoy writing their own versions of flatten more than finding legitimate use cases that don't already have trivial solutions." from https://softwareengineering.stackexchange.com/questions/254279/why-doesnt-python-have-a-flatten-function-for-lists https://softwareengineering.stackexchange.com/questions/2542...
And, intuitively, when you don't want to provide a helper function, the user code gets longer.
Not that this is better or worse. It's just that, specifically, on the brevity aspect, Python code would generally becomes longer. Because, as you see in the quote, "People seem to enjoy writing their own versions of flatten".