On Sun, Jun 20, 2021 at 1:07 PM Christopher Barker
Flatten is used in numpy: Where it is a method, and goes all the way to one dimension.
I think it's worth keeping in mind the differences though. In NumPy, arr.flatten() doesn't even TOUCH the array itself. It is solely a manipulation of the `.shape` attribute. In essence, we could define it like this: arr.flatten = lambda a: a.reshape(reduce(mul, a.shape, 1)) Actual NumPy arrays don't allow attaching a monkey-patch method, but if they did that would be it. I guess this example relies on knowing that `.reshape` also doesn't touch the data though (in particular, zero memory copies). A builtin flatten can’t be the same, but it would be nice if it weren’t too
different. e.g. list(flatten(a_2d_array)) would do the same thing as list(a_2d_array.flatten()). For a builtin, perhaps it could take an optional integer “depth” parameter which would provide flexibility and be one way to control its behavior with strings.
I think that would be nice as a signature. I don't really care about builtin vs itertools, but something like `flatten(seq, depth=2)` would be handy. The question is really whether the default depth is 1 or sys.maxsize. Both have plausible cases. Some special depth like 2 or 3 could be useful at times, but definitely should not be default. -- The dead increasingly dominate and strangle both the living and the not-yet born. Vampiric capital and undead corporate persons abuse the lives and control the thoughts of homo faber. Ideas, once born, become abortifacients against new conceptions.