Flatten is used in numpy:

https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html?highlight=flatten#numpy.ndarray.flatten

Where it is a method, and goes all the way to one dimension. 

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. 

-CHB

On Sat, Jun 19, 2021 at 8:36 AM Marc-Andre Lemburg <mal@egenix.com> wrote:
On 19.06.2021 17:17, Serhiy Storchaka wrote:
> 19.06.21 18:12, Marc-Andre Lemburg пише:
>>> But there could be endless debate about whether flatten( ("x", "y") ) should
>>> return a list or a tuple...
>>
>> Have it return an iterator :-)
>
> flatten = itertools.chain.from_iterable

Well, like I said: modulo the discussion around what "flatten"
should mean, e.g. you will probably want to have flatten() go
a certain number of levels deep and not necessarily flatten
strings.

But yes, such a definition is certainly a good start.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Jun 19 2021)
>>> Python Projects, Coaching and Support ...    https://www.egenix.com/
>>> Python Product Development ...        https://consulting.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               https://www.egenix.com/company/contact/
                     https://www.malemburg.com/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/5C2JB3QU7E4S5MMRI7NCRSZ52MFKZCC5/
Code of Conduct: http://python.org/psf/codeofconduct/
--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython