3 ms·
it has always annoyed me that flatten isn't already part of itertools
by jdeaton 2y ago
it has always annoyed me that flatten isn't already part of itertools
- isoprophlex 2y agoAmen. For a language that gloats on about "flat is better than nested" you have to jump to too many hoops to get your stuff flattened.
- jdeaton 2y agook itertools has chain.from_iterable but that name is hard to remember
- Myrmornis 2y agoYes, I think it might have been a slight design mistake to make the variadic version the default. I've only very rarely used it, whereas I use chain.from_iterable a lot.
- jonathan_landy 2y agoIs np.flatten not a workable option in some cases?
- benkuykendall 2y agoMaybe in some cases, but the performance characteristics are way different. The functions in `more_itertools` return lazy generators, but it looks like `np.flatten` materializes the results in an ndarray.
- rnewme 2y agoIs np part of the itertools?
- benkuykendall 2y agonp is the standard alias for numpy, probably the most popular numerical and array processing library for python. So, no, not part of the standard lib at all. But a universal import for most users of the language in any science/stats/ml environment. That said, still a surprising place from which to import a basic stream processing function.
- vismit2000 2y agoIt's there in form of chain: from itertools import chain flatten = chain.from_iterable Ref: pytudes - https://github.com/norvig/pytudes/blob/main/ipynb/Advent-2020.ipynb https://github.com/norvig/pytudes/blob/main/ipynb/Advent-202...